t = int(input()) x,a = map(int,input().split()) y,b = map(int,input().split()) ans = float("inf") if t >= 0: for i in range(t+1): back = b*i z = t+back ans = min(ans, y*i+(z//a)*x + z%a) else: t *= -1 for i in range(10**7): fwd = a*i if fwd > 10**7: break z = t + fwd ans = min(ans, y*((z+b-1)//b) + b*((z+b-1)//b)-z) print(ans)