#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int n, A, B, C;
vector<long long int> arr;
long long int rec(long long int cur, long long int a, long long int b,
                  long long int c) {
  if (cur == n) {
    if (min(a, min(b, c)) > 0) {
      return abs(a - A) + abs(b - B) + abs(c - C) - 30;
    } else
      return INT_MAX;
  }
  long long int r1 = rec(cur + 1, a, b, c);
  long long int r2 = rec(cur + 1, a + arr[cur], b, c) + 10;
  long long int r3 = rec(cur + 1, a, b + arr[cur], c) + 10;
  long long int r4 = rec(cur + 1, a, b, c + arr[cur]) + 10;
  return min(min(r1, r2), min(r3, r4));
}
int main() {
  srand(chrono::steady_clock::now().time_since_epoch().count());
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> A >> B >> C;
  cout << rec(0, 0, 0, 0);
  return 0;
}
