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