#include <string>
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	int N, M; string S;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }
		
		cin >> M >> S;

		vector<int> IOI;

		for (int i = 2; i < M; i++)
		{
			if (S[i - 2] == 'I' && S[i - 1] == 'O' && S[i] == 'I')
			{
				IOI.push_back(i);
			}
		}

		int count_ = (N == 1 && IOI.size() != 0) ? 1 : 0;
		int connect = 1;

		for (int i = 1; i < IOI.size(); i++)
		{
			if (IOI[i - 1] + 2 == IOI[i])
			{
				connect++;
			}
			else
			{
				connect = 1;
			}

			if (connect >= N)
			{
				count_++;
			}
		}

		cout << count_ << endl;
	}

	return 0;
}