#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pdd = pair; using pll = pair; using pli = pair; using pil = pair; template using Graph = vector>; const int MOD = 1e9 + 7; const ld PI = acos(-1); int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; int cnt = 0; bool isok = false; for (int i = 0; i < S.size(); ++i) { if (i <= S.size() - 3 && S.substr(i, 3) == "pon") { cnt++; } if (i <= S.size() - 4 && S.substr(i, 4) == "pain") { isok = true; break; } } if (!isok || cnt < 2) { cout << -1 << endl; } else { cout << cnt - 1 << endl; } return 0; }