t = int(input()) x, a = map(int, input().split()) y, b = map(int, input().split()) if t < 0: t = abs(t) q = (t + b - 1) // b ans = q * y r = q * b - t q, rr = divmod(r, a) ans += min((q - (rr != 0)) * x + (a - rr) % a, r) else: q, r = divmod(t, a) ans = q * x + r q += 1 res = q * x r = q * a - t q, rr = divmod(r, b) res += (q + (rr != 0)) * y + (b - rr) % b ans = min(ans, res) print(ans)