N = int(input()) A1, B1 = map(int,input().split()) A2, B2 = map(int,input().split()) A3, B3 = map(int,input().split()) 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( t // A1 * B1 + p + q for p, s in zip(range(0, A1 * B2, B2), range(N, -1, -A2)) for q, t in zip(range(0, A1 * B3, B3), range(s, -1, -A3)) ) )