T = int(input()) X,A = map(int, input().split()) Y,B = map(int, input().split()) ans = 10**20 for y in range(10**7+10): day = -y*B if T>=day: x = (T-day)//A ans = min(ans,y*Y+(T-day),y*Y+x*X+abs(T-(y*A-x*B))) print(ans)