S=input() pon="pon" pain="pain" memo=0 memo_pain=0 for i in range(len(S)-3): if S[i]!="p": pass elif S[i:i+4]==pain: memo_pain+=1 break elif S[i:i+3]==pon: memo+=1 if memo_pain==1: if memo>=2: print(memo-1) else: print(-1) else: print(-1)