n=eval(input()) ls=[] for i in range(3): ls.append(list(map(eval, input().split()))) for i in range(3): ls[i]= (n // ls[i][0])*ls[i][1] if n % ls[i][0] == 0 else ((n // ls[i][0])+1)*ls[i][1] print(min(ls))