/** * @FileName a.cpp * @Author kanpurin * @Created 2022.10.17 02:49:03 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; constexpr long long LLINF = 1e18 + 1; int main() { int t;cin >> t; int x,a,y,b;cin >> x >> a >> y >> b; ll ans = LLINF; for (int i = max(0,(b-1-t)/b); i <= 20000001; i++) { ll j = max(0LL,((ll)b*i+t+a-1)/a); ans = min(ans,(x-a)*j+(ll)(y+b)*i+t); } cout << ans << endl; return 0; }