import heapq t=int(input()) x,a=map(int,input().split()) y,b=map(int,input().split()) V={0} que=[(0,0)] heapq.heapify(que) MAX=10**7+100 while 1: val,now=heapq.heappop(que) if now==t: print(val) break vx=now+a if abs(vx)<2*MAX and not vx in V: heapq.heappush(que,(val+x,vx)) V.add(vx) vx=now-b if abs(vx)<2*MAX and not vx in V: heapq.heappush(que,(val+y,vx)) V.add(vx) vx=now+1 if abs(vx)<2*MAX and not vx in V: heapq.heappush(que,(val+1,vx)) V.add(vx)