def main(): s = input() if s.find("pain") == -1: print(-1) exit() cnt = 0 while True: if s[0:4] == "pain": break if s[0:3] == "pon": s = s[3:] cnt += 1 else: s = s[1:] result = -1 if cnt < 2 else cnt-1 print(result) if __name__ == "__main__": main()