#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	string S;
	for(;;){
		cin >> n;
		if(n == 0) break;
		cin >> m;
		cin >> S;
		int ans = 0;
		for(int i = 0; i < m; i++){
			int cnt = 0;
			while(S[i] == 'I' && S[i + 1] == 'O' && S[i + 2] == 'I'){
				cnt++;
				i += 2;
			}
			ans += max(0, cnt - n + 1);
		}
		cout << ans << endl;
	}
	return 0;
}