#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int m; string s;
        cin >> m >> s;

        int c = 0, res = 0;
        for (int i=0; i<m; ++i) {
            if (s[i] == 'I') {
                if (i == 0 || s[i-1] != 'O') {
                    c = 1;
                } else {
                    c ++;
                    if (n < c) res ++;
                }
            } else {
                if (i == 0 || s[i-1] != 'I') {
                    c = 0;
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}