#include<cstdio>
using namespace std;

char c[1000000];

int main(){

  int n,m;
  scanf("%d",&n);
  while(n != 0){
    scanf("%d",&m);
    scanf("%s",c);
    int ans = 0,flag;
    for(int i=0;i<m-2*n;i++){
      if(c[i] == 'I'){
	flag = 0;
	for(int j=i+1;j<m;j=j+2){
	  if(c[j]=='O'&&c[j+1]=='I'){
	    flag++;
	  } else{
	    break;
	  }
	}
	if(flag >= n){
	  ans += flag-n+1;
	}
	i += flag*2;
      }
    }
    printf("%d\n",ans);
    scanf("%d",&n);
  }

  return (0);
}