#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, m;
	while (cin >> n, n) {
		cin >> m;
		string s;
		cin >> s;
		vector<int> dp(m + 1);
		int res = 0;
		for (int i = 0; i < m; i++) {
			if (s[i] == 'I' && i - 2 >= 0 && s.substr(i - 2, 3) == "IOI") {
				dp[i + 1] = dp[i - 1] + 1;
				if (dp[i + 1] >= n) {
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

