#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long r = 0;
  long long n = (c / wr);
  for (int i = n; i >= max(0ll, n - 1000000); i--) {
    long long s = c - i * wr;
    r = max(r, i * hr + hb * (s / wb));
  }
  n = (c / wb);
  for (int i = n; i >= max(0ll, n - 1000000); i--) {
    long long s = c - i * wb;
    r = max(r, i * hb + hr * (s / wr));
  }
  cout << r << endl;
  return 0;
}
