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