#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	for (int h = 0; h < 10; h++) {
		long long n, m, a = 0, sum = 0, ans = 0; string s; cin >> n;
		if(n==0){
		    return 0;
		}
		cin>>m>>s;
		int test[123456] = { 0 };
		for (int h = 0; h < m - 2; h++) {
			if (s[h] == 'I' && s[h + 1] == 'O' && s[h + 2] == 'I') {
				sum++; h += 1;
			}
			else if (sum != 0) {
				test[a] = sum;
				a++; sum = 0;
			}
		}
		test[a] = sum;
		a++;

		for (int h = 0; h < a; h++) {
			if (test[h] >= n) {
				ans += test[h] - n + 1;
			}
		}
		cout << ans << endl;
	}
}

