t = int(input())
x, a = map(int, input().split())
y, b = map(int, input().split())

x = min(x, a)

ans = 10**20

if t >= 0:
    for c2 in range(10**7 + 1):
        now = c2*a
        cost = c2*x
        if now <= t:
            cost += t - now
        else:
            c3 = (now - t + b - 1)//b
            now -= c3*b
            cost += c3*y + t - now
        ans = min(ans, cost)
else:
    c3 = (-t + b - 1)//b
    for _ in range(10**7 + 1):
        cost = c3*y
        now = -c3*b
        c2 = (t - now)//a
        cost += c2*x
        now += c2*a
        cost += t - now
        ans = min(ans, cost)
        c3 += 1
print(ans)