#include <bits/stdc++.h>
using namespace std;
int N, A, B, C;
int l[8];
int dfs(int k, int a, int b, int c) {
  int ans = 1e9;
  if (k == N) {
    if (a == 0 || b == 0 || c == 0) return 1e9;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }
  ans = min(2, 3);
  ans = min({dfs(k + 1, a, b, c), dfs(k + 1, a + l[k], b, c),
             dfs(k + 1, a, b + l[k], c), dfs(k + 1, a, b, c + l[k])});
  return ans;
}
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin >> N >> A >> B >> C;
  for (int i = 0; i < 8; i++) {
    cin >> l[i];
  }
  cout << dfs(0, 0, 0, 0) << "\n";
}
