#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
	int n,m;
	char s[1000005];
	while(scanf("%d",&n),n!=0){
		scanf("%d%s",&m,s);
		vector<int> p;
		int i=0;
		while(i<m-2){
			int count=0;
			while(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I'){ count++; i+=2; if(i>=m-2) break;}
			if(count) p.push_back(count);
			i++;
		}
		int res=0;
		for(int i=0;i<p.size();i++) res+=max(0,p[i]-n+1);
		printf("%d\n",res);
	}
}