t = int(input()) x, a = map(int, input().split()) y, b = map(int, input().split()) ans = float("inf") for i in range(10**7): now = a * i tmp = x * i if now < t: tmp += t - now else: tmp += -((t - now) // b) * y tmp += (t - now) % b ans = min(ans, tmp) print(ans)