#include "stdio.h"

int N, M;
char letter[1000001] = {};
int num[1000001] = {};
int ans;

int main() {
	scanf("%d", &N);
	while (N != 0) {
		scanf("%d", &M);
		ans = 0;
		for (int i = 0; i < M; i++) {
			num[i] = 0;
		}
		scanf("%s", letter);
		for (int i = 0; i < M-2; i++) {
			if (letter[i] == 'I') {
				for (int j = 1; i + j < M; j++) {
					if (j % 2 == 1) {
						if (letter[i + j] != 'O')break;
					}
					else {
						if (letter[i + j] != 'I')break;
						num[i]++;
					}
				}
				if (num[i] > 0) {
					i += num[i] * 2;
				}
			}
		}
		for (int i = 0; i < M; i++) {
			if (num[i] >= N) {
				ans += num[i] - N + 1;
			}
		}
		printf("%d\n", ans);
		scanf("%d", &N);
	}
	return 0;
}