#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
map<char, int> m;
for (auto c : s)
m[c]++;
if(m['k'] > 0 && m['a'] > 0)
cout << min({ m['k'] - 1, (m['a'] - 1) / 2, m['p'], m['n'] }) << endl;
else
cout << "0" << endl;
return 0;
}