def co_solve(n, a0, b0, a1, b1, a2, b2): return max([ max([ (dj // a0) * b0 + i * b1 + j * b2 for j, dj in zip(range(a0), range(di, 0, -a2)) ]) for i, di in zip(range(a0), range(n, 0, -a1)) ]) 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)