#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int m, result = 0;
    string s;
    cin >> m >> s;
    s += "  ";
    for (int i = 0; i < m; i++)
      if (s[i] == 'I') {
        int count = 0;
        while (s[i+1] == 'O' && s[i+2] == 'I') {
          count++;
          i += 2;
        }
        result += max(0, count + 1 - n);
      }
    cout << result << endl;
  }
}