let s = stdin.ReadLine () let mutable pon_count = 0 let mutable prev = 'n' for i in 0..s.Length-1 do if s.[i..i+3] = "pain" then printfn "%d" (if pon_count < 2 then -1 else pon_count - 1) exit 0 else match prev, s.[i] with | 'n', 'p' -> prev <- 'p' | 'p', 'o' -> prev <- 'o' | 'o', 'n' -> prev <- 'n' pon_count <- pon_count + 1 | _ -> () printfn "-1"