loop do
  n = gets.to_i
  break if n == 0
  m = gets.to_i
  s = gets.chomp
  pn = "I" + "OI" * n

  cnt = 0
  idx = 0
  loop do
    idx = s.index pn, idx+1
    idx ? cnt += 1 : break
  end

  puts cnt
end