#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n,m;
string s;
int main(void){
  while(1){
    cin >> n;
    if(!n) break;
    cin >> m >> s;

    int ret = 0;
    int c = 0;
    for(int i = 0; i < m; i++){
      if(!c){
	if(s[i] == 'I'){
	  c = 1;
	}
      }else{
	if(s[i] == 'O' && s[i+1] == 'I'){
	  i++;
	  c++;
	}else{
	  ret += max(0,c - n);
	  c = 0;
	  i--;
	}
      }
    }
    cout << ret << endl;
  }
}