#include <bits/stdc++.h>
using namespace std;
long long c, Hr, Hb, Wr, Wb;
void solve() {
  long long ans = 0;
  long long i;
  for (i = 0; i * i <= c && Wr * i <= c; i++) {
    ans = max(ans, Hr * i + (c - Wr * i) / Wb * Hb);
  }
  cout << ans << endl;
}
int main(void) {
  while (scanf("%I64d %I64d %I64d %I64d %I64d", &c, &Hr, &Hb, &Wr, &Wb) !=
         EOF) {
    double unita = 1.0 * Hr / Wr, unitb = 1.0 * Hb / Wb;
    if (Wr * Wr < c && ((unita > unitb) || Wb * Wb >= c)) {
      long long temp1 = Wr;
      long long temp2 = Hr;
      Wr = Wb;
      Hr = Hb;
      Wb = temp1;
      Hb = temp2;
    }
    solve();
  }
  return 0;
}
