main = do
    n <- readLn
    if n == 0 then return () else do
        getLine -- skip length
        str <- getLine
        print $ count n str
        main

count :: Int -> String -> Int
count n s = count' (-1) s 0
    where
    count' _ "" t = t
    count' (-1) ('I':s) t = count' 0 s t
    count' (-1) ('O':s) t = count' (-1) s t
    count' l ('O':'I':s) t = count' (l+1) s (if l+1 >= n then t+1 else t)
    count' l ('I':s) t = count' 0 s t
    count' l ('O':s) t = count' (-1) s t