#include <iostream>

using namespace std;

#define rep(i,x) for(int i=0;i<(x);++i)

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int N, M;
	string s;
	while (cin >> N, N) {
		cin >> M;
		cin >> s;

		int ans = 0;

		int cnt = 0;
		bool f = true;

		rep(i, M+1) {
			if (s[i] == 'I') {
				if (cnt >= N * 2 + 1) {
					ans += (cnt - N * 2 - 1) / 2 + 1;
				}
				cnt = 1;
				continue;
			}

			if (s[i] == 'O' && s[i + 1] == 'I') {
				cnt += 2;
				i++;
			} else {
				if (cnt >= N * 2 + 1) {
					ans += (cnt - N * 2 - 1) / 2 + 1;
				}
				cnt = 0;
			}
		}

		if (cnt >= N * 2 + 1) {
			ans += (cnt - N * 2 - 1) / 2 + 1;
		}

		cout << ans << endl;
	}
}