#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
int main() {
  long long C, Hr, Hb, Wr, Wb;
  while (cin >> C >> Hr >> Hb >> Wr >> Wb) {
    if (C < Wr && C < Wb) {
      cout << 0 << endl;
      continue;
    }
    if (C < Wr && C >= Wb) {
      cout << C / Wb * Hb << endl;
      continue;
    }
    if (C < Wb && C >= Wr) {
      cout << C / Wr * Hr << endl;
      continue;
    }
    long long ans = 0;
    for (long long i = 0; i * i <= C; ++i) {
      if (C - i * Wb >= 0) {
        ans = max(ans, i * Hb + (C - i * Wb) / Wr * Hr);
      }
      if (C - i * Wr >= 0) {
        ans = max(ans, i * Hr + (C - i * Wr) / Wb * Hb);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
