#include <bits/stdc++.h>
using namespace std;
void load() {}
void solve() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  long long l = c - wr * wb;
  if (l > 0) {
    if (hr * wb > hb * wr) {
      long long t = l / wr;
      ans += t * hr;
      c -= t * wr;
    } else {
      long long t = l / wb;
      ans += t * hb;
      c -= t * wb;
    }
  }
  if (wr > wb) {
    long long res = 0;
    for (long long i = 0; i * wr <= c; i++) {
      long long l = c - i * wr;
      long long t = l / wb;
      res = max(res, t * hb + i * hr);
    }
    ans += res;
  } else {
    long long res = 0;
    for (long long i = 0; i * wb <= c; i++) {
      long long l = c - i * wb;
      long long t = l / wr;
      res = max(res, t * hr + i * hb);
    }
    ans += res;
  }
  cout << ans << endl;
}
int main() {
  load();
  solve();
  return 0;
}
