S = input() ans = 0 p = "" for s in S: if p == "pon": ans += 1 p = "" elif p == "pain": break if s == "p" and p != "": p = "" p += s else: if p != "pain": print(-1) exit() if ans == 2: print(1) elif ans <= 2: print(-1) else: print(ans-1)