import sys input = sys.stdin.readline def read_values(): return tuple(map(int, input().split())) def main(): N = int(input()) A = [0] * 3 B = [0] * 3 for i in range(3): A[i], B[i] = read_values() if A[1] * B[2] < A[2] * B[1]: A[1], A[2], B[1], B[2] = A[2], A[1], B[2], B[1] if A[0] * B[2] < A[2] * B[0]: A[0], A[2], B[0], B[2] = A[2], A[0], B[2], B[0] ans=0 for i in range(A[2]): for j in range(A[2]): use = i*A[0]+j*A[1] if use>N: break ans=max(ans,i*B[0]+j*B[1]+(N-use)//A[2]*B[2]) print(ans) if __name__ == "__main__": main()