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
  dfs = lambda do |x, y, c|
    land[y][x] = nil
    [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |i, j|
      a, b = x + i, y + j
      dfs[a, b, c] if 0 <= a && a < w && 0 <= b && b < h && land[b][a] == c
    end
  end
  r = 0
  h.times do |y|
    w.times do |x|
      if land[y][x]
        r += 1
        dfs[x, y, land[y][x]]
      end
    end
  end
  p r
end