#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string p = "I";
		for (int i = 0; i < n; i++) {
			p += "OI";
		}
		int c;
		string b;
		cin >> c >> b;
		int counter = 0;
		int i = 0;
		while (b.find(p, i) != string::npos) {
			counter++;
			i = b.find(p, i) + 1;
		}
		cout << counter << endl;
	}
	return 0;
}