use std::io::BufRead;

fn main() {
    let input: Vec<_> = std::io::stdin()
        .lock()
        .lines()
        .collect::<Result<_, _>>()
        .unwrap();
    let (s, empty) = input.split_first().unwrap();
    assert!(empty.is_empty()); // 入力の 2 行目以降がないことをチェック
    {
        let s: Vec<_> = s.chars().collect();
        assert!(matches!(s.len(), 1..=200_000)); // 文字数をチェック
        assert!(s.iter().all(char::is_ascii_lowercase)); // 全て英小文字であることをチェック
    }
    fn solve(s: &str) -> Option<usize> {
        let end = s.find("pain")?;
        Some(1 + s[..end].matches("pon").count().checked_sub(2)?)
    }
    let ans: i32 = solve(s).map(|x| x as i32).unwrap_or(-1);
    println!("{}", ans);
}