loop do
    h, w = gets.split.map &:to_i
    break if h == 0
    a = (1..h).map { [nil] + gets.chomp.scan(/./) + [nil] }
    a.unshift [nil] * (w + 2)
    a << [nil] * (w + 2)
    count = 0
    (1..h).each do |i|
        (1..w).each do |j|
            next unless a[i][j]
            count += 1
            sym = a[i][j]
            stack = [[i, j]]
            until stack.empty?
                y, x = stack.pop
                next unless a[y][x] == sym
                a[y][x] = nil   
                stack += [[y+1,x],[y-1,x],[y,x-1],[y,x+1]]
            end
        end
    end
    p count
end 