#include <bits/stdc++.h>
using namespace std;
long long c, h[2], w[2];
void solve() {
  cin >> c >> h[0] >> h[1] >> w[0] >> w[1];
  long long ans = 0;
  for (int i = 0; i < (int)(1000000); ++i)
    if (w[0] * i <= c) ans = max(ans, h[0] * i + (c - w[0] * i) / w[1] * h[1]);
  for (int i = 0; i < (int)(1000000); ++i)
    if (w[1] * i <= c) ans = max(ans, h[1] * i + (c - w[1] * i) / w[0] * h[0]);
  cout << ans << endl;
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
  if (argc > 1 && fopen(argv[1], "r")) freopen(argv[1], "rt", stdin);
  solve();
  return 0;
}
