until (a = $<.gets.split.map(&:to_i)) == [0, 0]
  h, w = a
  field = Array.new(h) {$<.gets.chomp.chars}
  
  erase = ->(x, y, fruit) {
    stack = [[x, y]]
    while (a = stack.shift)
      x, y = a
      next if x < 0 or x >= w or y < 0 or y >= h
      f = field[y][x]
      next unless f == fruit
      field[y][x] = "."
      [[1, 0], [0, -1], [-1, 0], [0, 1]].each do |dx, dy|
        stack << [x + dx, y + dy]
      end
    end
  }
  
  num = 0
  i = 0
  loop do
    x, y = i % w, i / w
    i += 1
    unless field[y][x] == "."
      erase.(x, y, field[y][x])
      num += 1
    end
    break if i >= w * h
  end
  puts num
end
