loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? and w.zero?
  land = []
  h.times do
    land << gets.chomp.chars
  end
  r = 0
  h.times do |y|
    w.times do |x|
      if land[y][x]
        r += 1
        c, stack = land[y][x], [[x, y]]
        until stack.empty?
          p, q = stack.pop
          land[q][p] = nil
          [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |i, j|
            a, b = p + i, q + j
            stack << [a, b] if 0 <= a && a < w && 0 <= b && b < h && land[b][a] == c
          end
        end
      end
    end
  end
  p r
end