#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
int main() {
  int n, a, b, c;
  int ans = INF;
  int now = 0;
  int cnt[3] = {-1, -1, -1};
  int legth[3] = {0, 0, 0};
  int bind[3] = {0, 0, 0};
  bool id[2];
  cin >> n >> a >> b >> c;
  vector<int> l(n, 0);
  for (int bit = 0; bit < (1 << (n * 2)); bit++) {
    for (int i = 0; i < 3; i++) {
      legth[i] = 0;
      bind[i] = 0;
    }
    for (int i = 0; i < (n); i++) {
      id[0] = (bit & (1 << (n * 2)));
      id[1] = (bit & (1 << (1 + n * 2)));
      switch (id[0] * 2 + id[1]) {
        case 0:
          legth[0] += l[i];
          bind[0]++;
          break;
        case 1:
          legth[1] += l[i];
          bind[1]++;
          break;
        case 2:
          legth[2] += l[2];
          bind[2]++;
          break;
      }
      if (bind[0] && bind[1] && bind[2]) {
        chmin(ans, abs(a - legth[0]) + abs(b - legth[1]) + abs(c - legth[2]) +
                       (bind[0] - 1) * 10 + (bind[1] - 1) * 10 +
                       (bind[2] - 1) * 10);
      }
      clog << legth[0] << "  " << legth[1] << "  " << legth[2] << "   "
           << bind[0] << " " << bind[1] << " " << bind[2] << endl;
    }
  }
  cout << ans << endl;
}
