import sys input = sys.stdin.readline T=int(input()) X,A=map(int,input().split()) Y,B=map(int,input().split()) ANS=1<<100 if T>=0: ANS=T for i in range(3*10**7+5): rest=T+i*B if rest<0: continue k=rest//A ANS=min(ANS,i*Y+k*X+rest-k*A) print(ANS)