loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0
    futons = gets.split.map(&:to_i)
    temps = gets.split.map(&:to_i).sort

    total = [0]
    (1..2**n-1).each do |x|
        y = x & (x-1)
        i = Math.log2(x - y)
        total[x] = total[y] + futons[i]
    end

    table = []
    m.times do |k|
        t = temps[k]
        table << [(0..k).map {|i| temps[i]}.inject(:+)]
        (1..2**n-1).each do |x|
            if total[x] <= t
                table[-1][x] = (table.size >= 2 ? table[-2][x] : 0) + t - total[x]
            else
                min = (table.size >= 2 ? table[-2][x] : 0) + total[x] - t
                (0..n-1).each do |i|
                    next if x[i] == 0
                    y = x - (1 << i)
                    m = table[-1][y]
                    min = m if m < min
                end
                table[-1][x] = min
            end
        end
    end
    p table[-1][-1]
end