import sys input=lambda:sys.stdin.readline().rstrip() S=input() N=len(S) ans=S[0:3]=='pon' for i in range(4,N+1): ans+=S[i-3:i]=='pon' if S[i-4:i]=='pain': print(ans-1 if ans>1 else -1) sys.exit() print(-1)