# AOJ 0538: IOIOI

# Python3 2018.7.1 bal4u



while True:

	n = int(eval(input()))

	if n == 0: break

	m = int(eval(input()))

	s = input().strip()

	ans = cnt = i = 0

	while i < m:

		if i+1 < m and s[i:i+2] == 'IO':

			cnt += 1

			i += 1

		elif cnt > 0:

			if s[i] == 'O': cnt -= 1

			if cnt >= n: ans += cnt-n+1

			cnt = 0

		i += 1

	print(ans)



# AOJ 0538: IOIOI

# Python3 2018.7.1 bal4u



import sys

from sys import stdin

input = stdin.readline



while True:

	n = int(eval(input()))

	if n == 0: break

	m = int(eval(input()))

	s = input().strip()

	ans = cnt = i = 0

	while i < m:

		if i+1 < m and s[i:i+2] == 'IO':

			cnt += 1

			i += 1

		elif cnt > 0:

			if s[i] == 'O': cnt -= 1

			if cnt >= n: ans += cnt-n+1

			cnt = 0

		i += 1

	print(ans)



# AOJ 0538: IOIOI
# Python3 2018.7.1 bal4u
while True:
    n = int(eval(input()))
    if n == 0:
        break
    m = int(eval(input()))
    s = input().strip()
    ans = cnt = i = 0
    while i < m:
        if i + 1 < m and s[i : i + 2] == "IO":
            cnt += 1
            i += 1
        elif cnt > 0:
            if s[i] == "O":
                cnt -= 1
            if cnt >= n:
                ans += cnt - n + 1
            cnt = 0
        i += 1
    print(ans)

# AOJ 0538: IOIOI
# Python3 2018.7.1 bal4u
import sys
from sys import stdin

input = stdin.readline
while True:
    n = int(eval(input()))
    if n == 0:
        break
    m = int(eval(input()))
    s = input().strip()
    ans = cnt = i = 0
    while i < m:
        if i + 1 < m and s[i : i + 2] == "IO":
            cnt += 1
            i += 1
        elif cnt > 0:
            if s[i] == "O":
                cnt -= 1
            if cnt >= n:
                ans += cnt - n + 1
            cnt = 0
        i += 1
    print(ans)

+import sys +from sys import stdin + +input = stdin.readline