#include <bits/stdc++.h>
using namespace std;
long long magic = 31623;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  if (max(wr, wb) > magic) {
    if (wr < wb) {
      swap(hr, hb);
      swap(wr, wb);
    }
    for (int x = 0;; x++) {
      if (x * wr > c) break;
      ans = max(ans, x * hr + (((c - x * wr) / wb) * hb));
    }
  } else {
    double rr = ((double)hr) / ((double)(wr));
    double bb = ((double)hb) / ((double)(wb));
    if (rr > bb) {
      swap(hr, hb);
      swap(wr, wb);
    }
    for (int x = 0; x < magic; x++) {
      if (x * wr > c) break;
      ans = max(ans, x * hr + (((c - x * wr) / wb) * hb));
    }
  }
  cout << ans;
  return 0;
}
