S = input() if "pain" not in S: print(-1) exit() S = S.split("pain")[0] x = S.count("pon") if x <= 1: print(-1) else: print(x - 1)