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): before = -T-y*B if before<=0: x = abs(before)//A ans = min(ans,y*Y-before,y*Y+x*X+abs(T-(y*A-x*B))) print(ans)