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