#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb, tmp, ret;
void iter(long long a, long long va, long long b, long long vb) {
  ret = 0;
  for (int i = 0; i * a <= c; ++i) {
    tmp = i * va + (c - i * a) / b * vb;
    if (tmp > ret) ret = tmp;
  }
}
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr * wr >= c)
    iter(wr, hr, wb, hb);
  else if (wb * wb >= c)
    iter(wb, hb, wr, hr);
  else {
    if (hb * wr < hr * wb) {
      ret = 0;
      for (int i = 0; i * i <= c && i * wb <= c; ++i) {
        tmp = i * hb + (c - i * wb) / wr * hr;
        if (tmp > ret) ret = tmp;
      }
    } else {
      ret = 0;
      for (int i = 0; i * i <= c && i * wr <= c; ++i) {
        tmp = i * hr + (c - i * wr) / wb * hb;
        if (tmp > ret) ret = tmp;
      }
    }
  }
  cout << ret << endl;
}
