s = input() ans = -1 f = False for i in range(0, len(s)): if s[i:i + 3] == "pon": ans += 1 if s[i:i + 4] == "pain": f = True break print(ans if ans != 0 and f else -1)