#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long l = 0, r = c / wb, ans = 0;
  for (long long i = l; i <= min(r, (long long)1e6); i++)
    ans = max(ans, i * hb + ((c - wb * i) / wr) * hr);
  for (long long i = r; i >= max(l, r - (long long)1e6); i--)
    ans = max(ans, i * hb + ((c - wb * i) / wr) * hr);
  if (wb > wr) {
    swap(hb, hr);
    swap(wb, wr);
  }
  if (wr > 1e4) {
    for (long long cnt = 0; cnt * wr <= c; cnt++)
      ans = max(ans, cnt * hr + ((c - wr * cnt) / wb) * hb);
  }
  cout << ans;
  return 0;
}
