#include using namespace std; int main() { string S; cin >> S; int N = S.size(); int ans = 0; int flag = 0; for( int i = 0; i < N; i++ ) { if( i + 4 <= N && S.substr( i, 4 ) == "pain" ) { flag = 1; break; } if( i + 3 <= N && S.substr( i, 3 ) == "pon" ) { i += 2; ans++; } } if( flag == 0 || ans < 2 ) ans = -1; else ans--; cout << ans << endl; }