s = io.read() p = s:find("pain") if not p then print(-1) os.exit() end c = 0 a = 1 while true do a = s:find("pon", a) if a and a < p then c = c + 1 a = a + 1 else break end end print(2 <= c and c - 1 or -1)