import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._

  loop()
  @tailrec def loop(): Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0) return 
    val futon = readLine.trim.split(' ').map(_.toInt)
    val demand = readLine.trim.split(' ').map(_.toInt).sorted.toList
    val memo = Array.fill(1 << n){-1}
    println(solve(0, futon, demand, memo))
    loop()
  }
  def solve(futonSet: Int, futon: Array[Int], demand: List[Int], memo: Array[Int]): Int = {
    if (memo(futonSet) >= 0) return memo(futonSet)
    if (!futon.indices.exists(i ⇒ (futonSet & (1 << i)) == 0)) {
      memo(futonSet) = demand.sum - futon.sum * demand.length
      return memo(futonSet)
    }
    val low = futon.indices.filter(i ⇒ (futonSet & (1 << i)) != 0).map(futon).sum
    var min = Int.MaxValue
    for (next ← futon.indices if (futonSet & (1 << next)) == 0) {
      demand.span(_ <= low + futon(next)) match {
        case (l, rest) ⇒
          val confirmed = l.map{d ⇒ math.min(d - low, low + futon(next) - d)}.sum
          min = math.min(min, confirmed + solve(futonSet | (1 << next), futon, rest, memo))
      }
    }
    memo(futonSet) = min
    min
  }
}
