#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001;
long long ans = 0;
long long c, hb, hr, wr, wb;
void relax(long long cntb, long long cntr) {
  if (cntb >= 0 && cntr >= 0 && cntb * wb + cntr * wr <= c) {
    ans = max(ans, hr * cntr + hb * cntb);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  if (wb > MAXN) {
    for (int i = 0; i < MAXN * MAXN; i++) {
      long long cntb = i, cntr = (c - cntb * wb) / wr;
      relax(cntb, cntr);
    }
  } else {
    long long cntb = c / wb;
    for (int i = 0; i < 10 * MAXN * MAXN; i++) {
      long long cntr = (c - cntb * wb) / wr;
      relax(cntb, cntr);
      cntb--;
    }
    long long cntr = c / wr;
    for (int i = 0; i < 10 * MAXN * MAXN; i++) {
      long long cntb = (c - cntr * wr) / wb;
      relax(cntb, cntr);
      cntr--;
    }
  }
  cout << ans;
  return 0;
}
