T = int(input()) X, A = map(int, input().split()) Y, B = map(int, input().split()) ans = 10 ** 15 + 1 tmp = 10 ** 15 y = max(-(T//B),0) i = 0 ans = tmp x = (T + B * y) // A d = (T + B * y) % A tmp = X * x + Y * y + d ans = min(ans,tmp) #print(x, y, d, ans, tmp) while i < 10: if X > Y: x += 1 y = (A * x - T) // B d = (A * x - T) % B else: y += 1 x = (T + B * y) // A d = (T + B * y) % A tmp = X * x + Y * y + d ans = min(ans, tmp) #print(x, y, d, ans, tmp) i += 1 print(ans)