import sys input = sys.stdin.readline N=int(input()) AB=[list(map(int,input().split())) for i in range(3)] AB.sort(reverse=True) X=[AB[i][1]/AB[i][0] for i in range(3)] MAX=max(X) ind=X.index(MAX) a,b=AB[ind] xx=AB[0][0]*AB[1][0]*2 k=max(0,N-xx)//a ANS=k*b N-=k*a ANS2=0 for i in range(N//AB[0][0]+1): rest=N-i*AB[0][0] for j in range(rest//AB[0][1]+1): ANS2=max(ANS2,i*AB[0][1]+j*AB[1][1]+(rest-j*AB[1][0])//AB[2][0]*AB[2][1]) print(ANS+ANS2)