#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  while (cin >> c) {
    cin >> hr >> hb >> wr >> wb;
    long long ans = 0;
    double r = (double)hr / wr;
    double b = (double)hb / wb;
    if (b < r) {
      swap(wb, wr);
      swap(hb, hr);
    }
    long long maxw = wb, minw = wr, maxh = hb, minh = hr;
    if (wb < wr) {
      swap(maxw, minw);
      swap(maxh, minh);
    }
    long long total = min(c, minw * maxw);
    for (long long i = 0; i <= minw; ++i) {
      long long tmp = 0;
      long long t = total - i * maxw + (c - total) % wb;
      long long res = 0;
      if (t >= 0) {
        tmp = i * maxh + t / minw * minh;
        res = t - t / minw * minw;
      } else {
        tmp = total / minw * minh;
        res = total - total / minw * minw;
      }
      ans = max(ans, tmp + (c - total) / wb * hb);
    }
    cout << ans << endl;
  }
  return 0;
}
