### main

loop do
  n = gets.strip.to_i
  break if n == 0

  m = gets.strip.to_i
  s = gets.strip

  status = 0
  prvch = ''
  total = 0
  sublen = 0

  for i in (0...m)
    case s[i]
    when 'I'
      if status == 0
        status = 1
        sublen = 0
      elsif prvch == 'I'
        if sublen >= n
          total += sublen - n + 1
        end
        sublen = 0
      else
        sublen += 1
      end
    when 'O'
      if status == 1 && prvch == 'O'
        if sublen >= n
          total += sublen - n + 1
        end
        status = 0
      end
    end

    prvch = s[i]
  end

  puts total
end