#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n,m;
string s;

int main(){
	while(cin>>n){
		if(!n)return 0;
		cin>>m>>s;
		int a=0,b=0;
		for(int i=0;i<m;i++){
			if(s[i]=='I'&&b%2==0||s[i]=='O'&&b%2==1)b++;
			else{
				if(s[i]=='I')b=1;
				else b=0;
			}
			if(b%2==1&&b>=2*n+1)a++;
		}
		cout<<a<<endl;
	}
}