#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,A,B,C;
int ans = 0;
int L[10];
int dfs(int k, int a, int b, int c){
    ans = min(ans, dfs(k+1,a,b,c));
    ans = min(ans, dfs(k+1, a+L[k], b, c) + (a[k]>0 ? 10:0));
    ans = min(ans, dfs(k+1, a, b+L[k], c) + (b[k]>0 ? 10:0));
    ans = min(ans, dfs(k+1, a, b, c+L[k]) + (c[k]>0 ? 10:0));
    return ans;
}
int main(){
    cin >> N;
    cin >> a >> b >> c;
    int res = dfs();
    cout << ans << endl;
}

