
fun main(args:Array<String>):Unit {
    var n = readLine()!!.toInt()
    while (n != 0){
        readLine()!!.toInt()
        val s = readLine()!!.trim()
        val memo = Array(s.length){0}
        for (i in 2 until memo.size){
            if (s[i - 2] == 'I' && s[i - 1] == 'O' && s[i] == 'I'){
                memo[i] = memo[i - 2] + 1
            }
        }
        println(memo.count{it >= n})
        n = readLine()!!.toInt()
    }
}

