#include using namespace std; using ll=long long; template T floor(T x, U y){return (x>0 ? x/y: (x-y+1)/y);} template T ceil(T x, U y){return (x>0 ? (x+y-1)/y: x/y);} template pair divmod(T x, U y){ T q=floor(x,y); return {q,x-q*y}; } int main(){ ll T,A,B,X,Y; cin >> T >> X >> A >> Y >> B; ll Ans=1001001001001001001; for (int r=0; r<=30000000; r++){ ll q,p; tie (q,p)=divmod(T+r*B, A); Ans=min(Ans, p+q*X+r*Y); } cout << Ans << endl; }