#include<cstdio>
#include<algorithm>
#include<cstring>
char str[1000011]={0};
int dp[1000011]={0};
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        memset(str,0,sizeof(str));
        int m;
        scanf("%d",&m);
        for(int i = 0;i < m; i++){
            scanf(" %c",str + i + 1);
        }
        int ans = 0;
        memset(dp,0,sizeof(dp));
        for(int i = 1; i<= m; i++){
            if(str[i-1] == 'I'&&str[i] == 'O'&&str[i+1] == 'I'){
                dp[i] = dp[i-2] + 1;
                if(dp[i] >= n)ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}