I,R,P=input,range,print def J(): return map(int,I().split()) N=int(I()) A,B,C=J() d=0 for c in R(N//10+1): n=N-c*10 for b in R(min(3,n//5+1)): m=n-b*5 d=max(d,c*C+b*B+(m//3)*A) for a in R(min(5,n//3+1)): m=n-a*3 d=max(d,c*C+(m//5)*B+a*A) P(d)