def main(): s = str(input()) n = len(s) stack = [] Flag = 0 for i in range(n): if i+4 <= n and s[i:i+4] == "pain": Flag = 1 break else: stack.append(s[i]) #print(stack) if Flag == 0: print(-1);exit() ans = 0 while len(stack) >= 3: if stack[-3] == "p" and stack[-2] == "o" and stack[-1] == "n": ans += 1 stack.pop() stack.pop() stack.pop() else: stack.pop() if ans >= 2: print(ans-1) else: print(-1) if __name__ == '__main__': main()