loop {
    n = gets.to_i
    break if n == 0
    gets
    str = gets.chomp
    chunks = str.scan(/((IO)+I)/).map{|s, _| (s.size - 1) / 2}
    count = 0
    chunks.each{|c|
        count += c - n + 1 if c >= n
    }
    p count
}