from array import array;

while True:

    n = int(input())

    if n == 0:

        break

    m = int(input())



    s = input()



    cache = array('i', (0 for x in range(m)))



    for i in range(len(s) - 2):

        if s[i:i+3] == 'IOI':

            cache[i + 2] = cache[i] + 1



    print(len([x for x in cache if x >= n]))
from array import array;

while True:

    n = int(input())

    if n == 0:

        break

    m = int(input())



    s = input()



    cache = array('i', (0 for x in range(m)))



    for i in range(len(s) - 2):

        if s[i:i+3] == 'IOI':

            cache[i + 2] = cache[i] + 1



    print(sum(1 for x in cache if x >= n))
from array import array

while True:
    n = int(input())
    if n == 0:
        break
    m = int(input())
    s = input()
    cache = array("i", (0 for x in range(m)))
    for i in range(len(s) - 2):
        if s[i : i + 3] == "IOI":
            cache[i + 2] = cache[i] + 1
    print(len([x for x in cache if x >= n]))

from array import array

while True:
    n = int(input())
    if n == 0:
        break
    m = int(input())
    s = input()
    cache = array("i", (0 for x in range(m)))
    for i in range(len(s) - 2):
        if s[i : i + 3] == "IOI":
            cache[i + 2] = cache[i] + 1
    print(sum(1 for x in cache if x >= n))

-    print(len([x for x in cache if x >= n])) +    print(sum(1 for x in cache if x >= n))