s = input() if "pain" not in s: print(-1) else: for i in range(len(s)): if s[i:i+4] == "pain": j = i break t = s[:j] cnt = 0 for i in range(len(t)): if t[i:i+3] == "pon": cnt += 1 if cnt < 2: print(-1) elif cnt >= 2: print(cnt - 1)