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

  #dfs(map, i - 1, j) if i > 0 && map[i - 1][j] == c
  dfs(map, i, j - 1) if j > 0 && map[i][j - 1] == c
  dfs(map, i + 1, j) if map[i + 1] && map[i + 1][j] == c
  dfs(map, i, j + 1) if map[i][j + 1] && map[i][j + 1] == c
end

def solve(map)
  ans = 0
  0.upto(map.size - 1) do |i|
    0.upto(map[i].size - 1) do |j|
      unless map[i][j] == ' '
        dfs(map, 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(map)
end