#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long res = 0;
  for (long long w = 0; w < 2; ++w) {
    for (long long i = 0; i * wr <= c && i <= 10000000; ++i) {
      res = max(res, i * hr + hb * ((c - i * wr) / wb));
    }
    swap(hb, hr);
    swap(wb, wr);
  }
  cout << res << "\n";
  return 0;
}
