Problem: My futon

You bought N futons in preparation for your new life. The i-th futon has the warmth supply capacity of si. From the temperature forecast for the next M days, the warmth demand of dj is expected on the jth day. If the warmth is not enough or too much, the comfort will be impaired, so the absolute value of the difference between the sum of the warmth supply capacity of the futon on the j day and the dj is called the discomfort on the j day. To do. I want to make the total discomfort for M days as small as possible.

By the way, your room is unfortunately very small, with only a bed and a closet. Therefore, the only way to add one futon to the bed is to put the futon at the top of the closet on the top of the bed. Conversely, the only way to reduce one bed futon is to put the futon at the top of the bed at the top of the closet. There is no limit to the number of futons that can be moved per day, but only one can be moved at a time.

By the way, you plan to put the futon you bought in the closet. Only at this time can the futons be put in the closet in any order. How do you store your futon in the closet, and then how do you put it in and out every day so that you can spend your days comfortably? When minimizing the sum of discomfort for M days, find the value of that sum. There may be futons that have never been used, and there may be days when no futons are used.

Input

The input consists of multiple datasets. Each dataset has the following format.

> N M
> s1 s2 ... sN
> d1 d2 ... dM

The first line of the dataset is given an integer representing the number of futons N and the number of days M for which the temperature is predicted, separated by spaces. On the second line, N integers s1, s2, ..., sN are given separated by spaces, and si represents the warmth supply capacity of the i-th futon. On the third line, M integers d1, d2, ..., dM are given separated by spaces, and dj represents the warmth demand on day j. These integers satisfy 1 ≤ N ≤ 15, 1 ≤ M ≤ 100, 1 ≤ si, dj ≤ 1,000,000.

The end of the input is represented by a dataset of N = M = 0. Do not output for this dataset.

Output

For each dataset, output the minimum sum of discomfort for M days on one line.

Sample Input


1 1
Five
6
1 1
Five
2
1 1
20
Five
4 1
2 4 5 9
8
4 3
3 5 2 1
10 4 7
5 5
2 2 2 2 2
1 3 5 7 9
twenty five
twenty five
2 5 2 5 2
0 0

Output for Sample Input


1
2
Five
1
1
Five
Four


For the 5th case, put it in the closet with 5, 2, 3, 1 from the top, and take out 3 sheets on the 1st day | 10-(5 + 2 + 3) | = 0, 2 sheets on the 2nd day | 4 -5 | = Take out one sheet on the 1st and 3rd days | 7-(5 + 2) | = 0, for a total of 0 + 1 + 0 = 1.





Example

Input

1 1
5
6
1 1
5
2
1 1
20
5
4 1
2 4 5 9
8
4 3
3 5 2 1
10 4 7
5 5
2 2 2 2 2
1 3 5 7 9
2 5
2 5
2 5 2 5 2
0 0


Output

1
2
5
1
1
5
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i != (int)(s.size())-1) cout << " ";
  }
  cout << "\n";
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for(int i=0;i<(int)(v.size());++i) {
    if(i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
bool solve() {
  int n, m; cin >> n >> m;
  if(n == 0) return false;
  vi s(n), d(m), sud(m+1);
  for(int i=0;i<n;++i) {
    cin >> s[i];
  }
  for(int i=0;i<m;++i) {
    cin >> d[i];
  }
  sort(d.begin(),d.end());
  for(int i=0;i<m;++i) {
    sud[i+1] = sud[i] + d[i];
  }
  vi su(1<<n);
  for(int i=0;i<1<<n;++i) {
    for(int j=0;j<n;++j) {
      if(i>>j&1) {
        su[i] = su[i ^ (1<<j)] + s[j];
      }
    }
  }
  int ans = 0;
  for(int i=0;i<m;++i) {
    if(d[i] >= su[(1<<n)-1]) {
      ans += abs(d[i] - su[(1<<n)-1]);
    }
  }
  vi dp(1<<n, INF);
  dp[0] = 0;
  for(int bit=0;bit<1<<n;++bit) {
    for(int i=0;i<n;++i) {
      if((bit>>i)&1) {
        auto it1 = lower_bound(d.begin(),d.end(), su[bit^(1<<i)]);
        auto it2 = lower_bound(d.begin(),d.end(), su[bit]);
        int pos1 = distance(d.begin(), it1);
        int pos2 = distance(d.begin(), it2);
        int now = 0;
        for(int j=pos1;j<pos2;++j) {
          now += min(abs(d[j] - su[bit]), abs(d[j] - su[bit ^ (1<<i)]));
        }
        chmin(dp[bit], dp[bit^(1<<i)] + now);
      }
    }
  }
  cout << ans + dp[(1<<n)-1] << endl;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    if(!solve()) break;
  }
}