n = int(input()) [[a1, b1], [a2, b2], [a3, b3]] = [list(map(int, input().split())) for _ in range(3)] assert n > 0 and a1 > 0 and a2 > 0 and a3 > 0 and b1 > 0 and b2 > 0 and b3 > 0 if a2 * b1 < a1 * b2: a1, b1, a2, b2 = a2, b2, a1, b1 if a3 * b1 < a1 * b3: a1, b1, a3, b3 = a3, b3, a1, b1 print( max( max( dj // a1 * b1 + i + j for j, dj in zip(range(0, a1 * b3, b3), range(di, -1, -a3)) ) for i, di in zip(range(0, a1 * b2, b2), range(n, -1, -a2)) ) )