while True:

        n = eval(input())

        if n == 0:

            break

        m = eval(input())

        s = input()

        cur,score = 0,0

        for c in s:

            if cur <= 2*n:

                if cur % 2 == 0:

                    cur = cur+1 if c=="I" else 0

                else:

                    cur = 1 if c=="I" else cur+1

            elif cur == 2*n+1:

                score += 1

                cur = 1 if c=="I" else 2*n

        print(score)
while True:

        n = eval(input())

        if n == 0:

            break

        m = eval(input())

        s = input()

        graph = []

        for i in range(n):

            graph.append({"I":2*i+1,"O":0,"score":0})

            graph.append({"I":1,"O":2*(i+1),"score":0})

        graph.append({"I":2*n+1,"O":0,"score":0})

        graph.append({"I":1,"O":2*n,"score":1})

        cur,score = 0,0

        for c in s:

            cur = graph[cur][c]

            score += graph[cur]["score"]

        print(score)
while True:
    n = eval(input())
    if n == 0:
        break
    m = eval(input())
    s = input()
    cur, score = 0, 0
    for c in s:
        if cur <= 2 * n:
            if cur % 2 == 0:
                cur = cur + 1 if c == "I" else 0
            else:
                cur = 1 if c == "I" else cur + 1
        elif cur == 2 * n + 1:
            score += 1
            cur = 1 if c == "I" else 2 * n
    print(score)

while True:
    n = eval(input())
    if n == 0:
        break
    m = eval(input())
    s = input()
    graph = []
    for i in range(n):
        graph.append({"I": 2 * i + 1, "O": 0, "score": 0})
        graph.append({"I": 1, "O": 2 * (i + 1), "score": 0})
    graph.append({"I": 2 * n + 1, "O": 0, "score": 0})
    graph.append({"I": 1, "O": 2 * n, "score": 1})
    cur, score = 0, 0
    for c in s:
        cur = graph[cur][c]
        score += graph[cur]["score"]
    print(score)

+    graph = [] +    for i in range(n): +        graph.append({"I": 2 * i + 1, "O": 0, "score": 0}) +        graph.append({"I": 1, "O": 2 * (i + 1), "score": 0}) +    graph.append({"I": 2 * n + 1, "O": 0, "score": 0}) +    graph.append({"I": 1, "O": 2 * n, "score": 1}) -        if cur <= 2 * n: -            if cur % 2 == 0: -                cur = cur + 1 if c == "I" else 0 -            else: -                cur = 1 if c == "I" else cur + 1 -        elif cur == 2 * n + 1: -            score += 1 -            cur = 1 if c == "I" else 2 * n +        cur = graph[cur][c] +        score += graph[cur]["score"]