#include<iostream>
#include<string>
#include<cstring>

int data[1000001];

int main(){
	int n;

	while (std::cin >> n, n){
		memset(data, 0, sizeof(data));

		int m;
		std::string str;
		std::cin >> m >> str;

		int res = 0;

		for (int i = m - 3; i >= 0; i--){
			if (str[i] == 'I'&&str[i + 1] == 'O'&&str[i + 2] == 'I')data[i] = data[i + 2] + 1;
		}

		for (int i = 0; i < m; i++){
			if (data[i] >= n)res++;
		}
		
		std::cout << res << std::endl;
	}

	return 0;
}