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 += q * x + rr q, r = divmod(t, b) ans = min(ans, (q + (r != 0)) * y + (b - r) % b) 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)