S = input() if "pain" not in S: print(-1) exit() i = S.index("pain") c = S[:i].count("pon") if c < 2: print(-1) else: print(c - 1)