#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, m;
  string s;
  while (true) {
    int p = 0;
    long long total = 0;
    cin >> n;
    if (n == 0) {
      return 0;
    }
    cin >> m >> s;
    while (p < m) {
      if (s[p] == 'I') {
        int count = 0;
        while (s.substr(p + 2 * count + 1, 2) == "OI") {
          ++count;
        }
        total += max(0, count - n + 1);
        p += 1 + 2 * count;
      } else {
        ++p;
      }
    }
    cout << total << endl;
  }
}