s = input() S = s.split("pain") if S[0].count("pon") >= 2 and "pain" in s: print(S[0].count("pon") - 1) exit() print(-1)