#yuki1534 s=input() pon=0 for i in range(len(s)): if s[i:i+3]=='pon': pon+=1 if s[i:i+4]=='pain': break if pon<=1 or i==len(s)-1: print(-1) else: print(pon-1)