#include <bits/stdc++.h>
using namespace std;
long long ca, le, c, ha, hb, wa, wb;
int main() {
  long long ans = 0;
  cin >> c >> ha >> hb >> wa >> wb;
  if (wa < wb) swap(wa, wb), swap(ha, hb);
  if (wa >= 30000) {
    for (int i = 0; i <= c / wa; i++)
      ans = max(ans, i * ha + (c - i * wa) / wb * hb);
    cout << ans << endl;
    return 0;
  }
  double xa, xb;
  xa = (double)ha / wa;
  xb = (double)hb / wb;
  if (xa > xb) swap(ha, hb), swap(wa, wb);
  for (int i = 0; i <= wb && i * wa <= c; i++)
    ans = max(ans, i * ha + (c - i * wa) / wb * hb);
  cout << ans << endl;
  return 0;
}
