#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	string s;
	int n,m,count;
	while(scanf("%d",&n)){
		if(n==0)
		break;
		string s1="IOI";
		scanf("%d",&m);
		cin >> s;
		for(int i=1;i<n;i++){
			s1.push_back('O');
			s1.push_back('I');
		}
		count = 0;
		for(int i=0;i<m;i++){
			if(s.substr(i,s1.size())==s1)
			count++;
		}
		printf("%d\n",count);
	}
}