def setit(c, x, y)
  $checker[y][x] = false
  dx = [0,0,1,-1]
  dy = [1,-1,0,0]
  0.upto(3) do |i|
    nx = x + dx[i]
    ny = x + dy[i]
    next if ny >= $orchard.size || ny < 0
    if c == $orchard[ny][nx] && $checker[ny][nx]
      setit(c, nx, ny)
    end
  end
end

loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?
  $orchard = []
  h.times { $orchard << gets.chomp.split('') }
  $checker = []
  h.times do
    temp = []
    w.times { temp << true }
    $checker << temp
  end
  count = 0

  $orchard.each_with_index do |l, y|
    l.each_with_index do |c, x|
      if $checker[y][x]
        count += 1
        setit(c, x, y)
      end
    end
  end

  puts count
end