#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  scanf("%I64d %I64d %I64d %I64d %I64d", &c, &hr, &hb, &wr, &wb);
  long long lim = sqrt(c), ans = 0, top;
  if (wr > lim || wb > lim) {
    if (wb < lim) {
      swap(wb, wr);
      swap(hb, hr);
    }
    top = c / wb + 1;
  } else {
    if (wr * hb > wb * hr) {
      swap(wb, wr);
      swap(hb, hr);
    }
    top = wr;
  }
  for (int i = 0; i < top; i++) {
    long long red = (c - wb * i) / wr;
    long long tmp = i * hb + red * hr;
    if (tmp > ans) {
      ans = tmp;
    }
  }
  printf("%I64d", ans);
  return 0;
}
