n,*z=map(int,open(0).read().split());z*=2;print(max(max(max(y//p*s+i*t+j*u for j,y in zip(range(p),range(x,0,-r)))for i,x in zip(range(p),range(n,0,-q)))for[p,s,q,t,r,u]in[z[0:6],z[2:8],z[4:10]]))