from heapq import heappop, heappush t = int(input()) x, a = map(int, input().split()) y, b = map(int, input().split()) dp = {0: 0} hq = [(0, 0)] while hq: _, p = heappop(hq) if p == t: break if p+1 not in dp or dp[p+1] > dp[p]+1: dp[p+1] = dp[p]+1 heappush(hq, (dp[p+1], p+1)) if p+a not in dp or dp[p+a] > dp[p]+x: dp[p+a] = dp[p]+x heappush(hq, (dp[p+a], p+a)) if p-b not in dp or dp[p-b] > dp[p]+y: dp[p-b] = dp[p]+y heappush(hq, (dp[p-b], p-b)) print(dp[t])