import numpy as np n = int(input()) [[a1, b1], [a2, b2], [a3, b3]] = [list(map(int, input().split())) for _ in range(3)] # 最大効率の割引を a1,b1 とする 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 # c1min : a1,b1 の割引の最低使用回数 c1min = max(n // a1 - a2 - a3, 0) # remain : c1min回を除いた残り枚数 remain = min(a1 * (a2 + a3) + (n % a1), n) print( max( int(np.max(((s - j * a3) // a1) * b1 + i * b2 + j * b3)) for i, j, s in zip( range(a1), map(lambda s: np.arange(0, min(a1, s // a3 + 1), dtype=np.uint32), range(remain, -1, -a2)), range(remain, -1, -a2), ) ) + c1min * b1 )