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

  dfs(i - 1, j) if i > 0      && @map[i - 1][j] == c
  dfs(i, j - 1) if j > 0      && @map[i][j - 1] == c
  dfs(i + 1, j) if i + 1 < @h && @map[i + 1][j] == c
  dfs(i, j + 1) if j + 1 < @w && @map[i][j + 1] == c
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