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) while ans > tmp: ans = tmp x = (T + B * y) // A d = (T + B * y) % A tmp = X * x + Y * y + d y += 1 print(ans)