#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef long long ll;

int n, m;
string s;
int c[1000001];

signed main()
{
	while (true) {
		cin >> n;
		if (n == 0) break;
		cin >> m;
		cin >> s;

		rep(i,1000001) c[i] = 0;
		//c[m-1] = c[m-2] = 0;

		for (int i=m-3; i>=0; i--) {
			if (s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I') {
				c[i] = c[i+2] + 1;
			}
		}

		int ans = 0;
		rep(i,m) {
			if (c[i] >= n) ans++;
		}

		cout << ans << endl;
	}
}