#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void upd(ll &a, ll b) {
  if (a < b) a = b;
}
int main() {
  ll c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  ll ans = 0;
  if (wb > 1000) {
    for (int i = 0; i * wb <= c; i++) upd(ans, i * hb + (c - i * wb) / wr * hr);
  } else {
    ll wc = wr * wb;
    ll hc = max(wb * hr, wr * hb);
    ll base = 0;
    if (c >= 2 * wc) {
      base = (c / wc - 1) * hc;
      c -= (c / wc - 1) * wc;
    }
    for (int i = 0; i * wb <= c; i++)
      upd(ans, i * hb + (c - i * wb) / wr * hr + base);
  }
  cout << ans << '\n';
}
