N=int(input())
AB=[list(map(int,input().split())) for _ in range(3)]

ls=[[AB[i][1]/AB[i][0],AB[i][0],AB[i][1]] for i in range(3)]
ls.sort()


ans=0
for i in range(2000):
    inum=ls[0][1]*i
    for j in range(2000):
        jnum=ls[1][1]*j
 
        if N-inum-jnum<0:
            continue
        k=(N-inum-jnum)//ls[2][1]
    
        tmp=i*ls[0][2]+j*ls[1][2]+k*ls[2][2]
        ans=max(ans,tmp)
        
print(ans)