#include <iostream>
using namespace std;

int main(){
    char s[1000000];
    int n,m;
    while(cin>>n,n){
        cin>>m>>s;
        int ans = 0;
        for(int i=0;i<m-n*2;++i){
            if(s[i]=='I'){
                for(int j=0;j<n;++j){
                    if(s[i+2*j+1]!='O'||s[i+2*j+2]!='I') break;
                    if(j==n-1) ++ans;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}