def dfs(i, j)
  c = @map[i][j]
  @map[i][j] = '.'

  stack = []
  stack.push [i, j]

  mv = [[-1, 0], [1, 0], [0, -1], [0, 1]]

  while !stack.empty?
    i, j = stack.pop

    mv.each do |mi, mj|
      ii = i + mi; jj = j + mj
      if 0 <= ii && ii < @h && 0 <= jj && jj < @w && @map[ii][jj] == c
        @map[ii][jj] = '.'
        stack.push [ii, jj]
      end
    end
  end
end

def solve
  ans = 0
  0.upto(@h - 1) do |i|
    0.upto(@w - 1) do |j|
      unless @map[i][j] == '.'
        dfs(i, j)
        ans += 1
      end
    end
  end
  ans
end

while true
  @h, @w = gets.split.map(&:to_i)
  break if @h == 0 && @w == 0

  @map = []
  @h.times do
    @map.push gets.chomp.split('')
  end

  puts solve
end