from sys import stdin def main(): input = lambda: stdin.readline()[:-1] S = input() s = S.split("pain") ans = s[0].count("pon") - 1 if len(s) == 1 or ans < 1: print(-1) else: print(ans) main()