S=input() C=0 for i in range(len(S)): if S[i:i+3]=='pon': C+=1 elif S[i:i+4]=='pain': if C<2: print(-1) else: print(C-1) exit() print(-1)