#include<iostream>
#include<string>

using namespace std;

int main()
{
	while (1){
		int n;
		cin >> n;
		if (!n){ break; }

		int m, counter = 0, sum = 0;
		string s;
		char want = 'I';
		cin >> m >> s;

		//from 1 to m-1
		for (int i = 0; i < m; i++){
			if (want == s[i]){
				counter++;
				want = (want == 'I') ? 'O' : 'I';
			}
			else{
				if ((counter - 1) / 2 - n + 1 > 0){
					sum += (counter - 1) / 2 - n + 1;
				}
				counter = 0;
				want = 'I';
				if (s[i] == 'I'){
					i--;
				}
			}
		}

		//last
		if ((counter - 1) / 2 - n + 1 > 0){
			sum += (counter - 1) / 2 - n + 1;
		}
		cout << sum << endl;
	}
	return 0;
}