S=input() if "pain" not in S: exit(print(-1)) x=S.index("pain") T=S[:x+4] m=0 for i in range(x): if T[i:i+3]=="pon": m+=1 print(m-1 if m>=2 else -1)