#encoding:utf-8 No.0538 2015.1.5
until (n = gets.chomp.to_i) == 0
  str_length = gets.chomp.to_i
  str = gets.chomp
  io = "IO"*n + "I"
  count = 0

  str_length.times do |i|
    if str[i,io.length] == io
      count += 1
    end
  end

  puts count
end