#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { string s, p1 = "pon", p2 = "pain"; ll cnt = 0; bool pain = false; cin >> s; for (int i = 0; i < s.size(); i++){ if (s[i] == 'p'){ if (s.substr(i, 3) == p1) cnt++; if (s.substr(i, 4) == p2){ pain = true; break; } } } if (pain && cnt >= 2) cout << cnt - 1 << endl; else cout << -1 << endl; }