while True:

  n = int(eval(input()))

  if not n: break

  m = int(eval(input()))

  s = eval(input())

  ind = 0

  ans = 0

  while ind < m:

    if s[ind] == "I":

      count = 0

      while ind + 2 < m:

        if s[ind + 1] == "O" and s[ind + 2] == "I":

          count += 1

          ind += 2

        else:

          break

      if count - n + 1 >= 0:

        ans += (count - n + 1)

    ind += 1

  print(ans)

def solve():

  while True:

    n = int(eval(input()))

    if not n: break

    m = int(eval(input()))

    s = eval(input())

    ind = 0

    ans = 0

    while ind < m:

      if s[ind] == "I":

        count = 0

        while ind + 2 < m:

          if s[ind + 1] == "O" and s[ind + 2] == "I":

            count += 1

            ind += 2

          else:

            break

        if count - n + 1 >= 0:

          ans += (count - n + 1)

      ind += 1

    print(ans)

solve()

while True:
    n = int(eval(input()))
    if not n:
        break
    m = int(eval(input()))
    s = eval(input())
    ind = 0
    ans = 0
    while ind < m:
        if s[ind] == "I":
            count = 0
            while ind + 2 < m:
                if s[ind + 1] == "O" and s[ind + 2] == "I":
                    count += 1
                    ind += 2
                else:
                    break
            if count - n + 1 >= 0:
                ans += count - n + 1
        ind += 1
    print(ans)

def solve():
    while True:
        n = int(eval(input()))
        if not n:
            break
        m = int(eval(input()))
        s = eval(input())
        ind = 0
        ans = 0
        while ind < m:
            if s[ind] == "I":
                count = 0
                while ind + 2 < m:
                    if s[ind + 1] == "O" and s[ind + 2] == "I":
                        count += 1
                        ind += 2
                    else:
                        break
                if count - n + 1 >= 0:
                    ans += count - n + 1
            ind += 1
        print(ans)


solve()

-while True: -    n = int(eval(input())) -    if not n: -        break -    m = int(eval(input())) -    s = eval(input()) -    ind = 0 -    ans = 0 -    while ind < m: -        if s[ind] == "I": -            count = 0 -            while ind + 2 < m: -                if s[ind + 1] == "O" and s[ind + 2] == "I": -                    count += 1 -                    ind += 2 -                else: -                    break -            if count - n + 1 >= 0: -                ans += count - n + 1 -        ind += 1 -    print(ans) +def solve(): +    while True: +        n = int(eval(input())) +        if not n: +            break +        m = int(eval(input())) +        s = eval(input()) +        ind = 0 +        ans = 0 +        while ind < m: +            if s[ind] == "I": +                count = 0 +                while ind + 2 < m: +                    if s[ind + 1] == "O" and s[ind + 2] == "I": +                        count += 1 +                        ind += 2 +                    else: +                        break +                if count - n + 1 >= 0: +                    ans += count - n + 1 +            ind += 1 +        print(ans) + + +solve()