T = int(input()) X,A = map(int, input().split()) Y,B = map(int, input().split()) ans = 10**20 for y in range(10**7*7): day = -y*B if T>=day: x = (T-day)//A ans = min(ans,y*Y+(T-day),y*Y+x*X+abs(T-(-y*B+x*A))) for x in range(10**7*7): day = T+x*A if day>=0: y = -(-day//B) ans = min(ans,y*Y+x*X+abs(T-(-y*B+x*A))) print(ans)