# coding: utf-8 # Your code here! N=int(input()) A,B,C=map(int,input().split()) dic={3:A,5:B,10:C} dp=[-1]*(N+1) dp[0]=0 for i in range(N): if dp[i]!=-1: for n,price in dic.items(): if i+n<=N: dp[i+n]=max(dp[i+n],dp[i]+price) print(max(dp))