S = gets.strip i = S.index("pain") if not i then puts -1 else n = S[0, i].scan("pon").length if n < 2 then puts -1 else puts n - 1 end end