loop do
  n, m = gets.split.map(&:to_i)
  break if n.zero? && m.zero?

  orchard = []
  n.times do
    orchard << gets.chomp.chars
  end
  angle = [1,0, 0,1, -1,0, 0,-1]
  count = 0

  0.upto(n-1) do |x|
    0.upto(m-1) do |y|
      next if orchard[x][y].nil?
      
      temp = [x, y]
      f = orchard[x][y]
      orchard[x][y] = nil

      loop do
        i = temp.shift
        j = temp.shift
        angle.each_slice(2) do |a, b|
          ii = a + i
          jj = b + j
          if (0..n-1).include?(ii) && (0..m-1).include?(jj) && f == orchard[ii][jj]
            temp << ii << jj
            orchard[ii][jj] = nil
          end
        end
        if temp.empty?
          count += 1
          break
        end
      end
    end
  end

  puts count
end