#include <iostream>
using namespace std;
int main()
{
	int n,m,ans;
	char IOI[1000001];
	while(cin>>n,n){
		cin>>m>>IOI;
		int i,k;
		ans = 0;
		n = 2*n+1;
		k=0;
		// 4__ IOIOIOIOI
		for(;;){
			for(i=0; i<n/2; i++){
				if( IOI[i+k]!=(i&1?'O':'I') ||
					 IOI[i+k]!=IOI[k+n-i-1] )
					break;
			}
			if( i==n/2 && IOI[k+n/2]==((n/2)%2?'O':'I')){
				//printf("k_%d IOI[%d]=%c\n",k,k+n/2,IOI[k+n/2]);
				ans++;
				k += n;
				for(; k<m; k+=2){
					if( IOI[k]=='O' && IOI[k+1]=='I' ){
						ans++;
						//printf("k__%d\n",k);
					}
					else break;
				}
			}else{
				for(k++; k<m && IOI[k]=='O'; k++);
			}
			//printf("next_k_%d\n",k);
			if( k+n>m )break;
		}
		printf("%d\n",ans);
	}
}