t = int(input()) x,a = map(int,input().split()) y,b = map(int,input().split()) import heapq inf = 10 ** 15 r = max(2*a,2*t) l = min(-b,t*2) vis = [inf] * (1 + r - l) q = [(0,0)] while q: cost,node = heapq.heappop(q) if vis[node] <= cost:continue vis[node] = cost if l <= node + a <= r: if vis[node+a] == inf: heapq.heappush(q,(cost+x,node + a)) if l <= node + 1 <= r: if vis[node+1] == inf: heapq.heappush(q,(cost+1,node + 1)) if l <= node - b <= r: if vis[node-b] == inf: heapq.heappush(q,(cost+y,node - b)) # print(q) print(vis[t])