#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-4;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  for (int i = 0; i < 20000; i++)
    if (wr * i <= c) ans = max(ans, hr * i + (c - wr * i) / wb * hb);
  for (int i = 0; i < 20000; i++)
    if (wb * i <= c) ans = max(ans, hb * i + (c - wb * i) / wr * hr);
  cout << ans << endl;
  return 0;
}
