n=int(input()) a,b,c=map(int,input().split()) dp=[-1]*(n+1) dp[0]=0 for i in range(n+1): if 0<=i-3 and 0<=dp[i-3]: dp[i]=max(dp[i],dp[i-3]+a) if 0<=i-5 and 0<=dp[i-5]: dp[i]=max(dp[i],dp[i-5]+b) if 0<=i-10 and 0<=dp[i-10]: dp[i]=max(dp[i],dp[i-10]+c) print(max(dp))