s = input() import sys pon1 = 0 pon2 = 0 pain1 = 0 for i in s: if i == "pon"[pon2]: pon2 += 1 else: pon2 = 0 pon1 = 0 if pon2 == 3: pon2 = 0 pon1 += 1 if i == "pain"[pain1]: pain1 += 1 else: pain1 = 0 if pain1 == 4: if pon1 == 0: print(-1) else: print(pon1) sys.exit() print(-1)