import numpy as np def co_solve(n, a0, b0, a1, b1, a2, b2): r = 0 for i in range(min(a0, n // a1 + 1)): d = n - i * a1 jmax = min(a0, d // a2 + 1) j = np.arange(0, jmax, dtype=np.uint64) t = ((d - j * a2) // a0) * b0 + i * b1 + j * b2 r = max(r, np.amax(t)) return r n = int(input()) a0, b0 = (int(x) for x in input().split()) a1, b1 = (int(x) for x in input().split()) a2, b2 = (int(x) for x in input().split()) result = max( co_solve(n, a0, b0, a1, b1, a2, b2), co_solve(n, a1, b1, a2, b2, a0, b0), co_solve(n, a2, b2, a0, b0, a1, b1), ) print(result)