n = int(input()) ab = [list(map(int, input().split())) for _ in range(3)] * 2 print( max( max( max( dj // ap * bp + ibq + jbr for jbr, dj in zip(range(0, ap * br, br), range(di, 0, -ar)) ) for ibq, di in zip(range(0, ap * bq, bq), range(n, 0, -aq)) ) for [[ap, bp], [aq, bq], [ar, br]] in [ab[0:3], ab[1:4], ab[2:5]] ) )