#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int num = 1000000;
int c, hr, hb, wr, wb;
long long res;
bool valid(long long r, long long b) {
  return (r >= 0 && b >= 0 && r < INF && b < INF &&
          1LL * wr * r + 1LL * wb * b <= c);
}
long long value(int r, int b) { return (1LL * hr * r + 1LL * hb * b); }
int main(void) {
  cin >> c >> hr >> hb >> wr >> wb;
  for (int r = (0), _b = (num); r <= _b; r = r + 1)
    if (valid(r, (c - 1LL * wr * r) / wb))
      res = max(res, value(r, (c - 1LL * wr * r) / wb));
  for (int b = (0), _b = (num); b <= _b; b = b + 1)
    if (valid((c - 1LL * wb * b) / wr, b))
      res = max(res, value((c - 1LL * wb * b) / wr, b));
  for (int r = (c / (wr + wb) - num), _b = (c / (wr + wb) + num); r <= _b;
       r = r + 1)
    if (valid(r, (c - 1LL * wr * r) / wb))
      res = max(res, value(r, (c - 1LL * wr * r) / wb));
  for (int b = (c / (wr + wb) - num), _b = (c / (wr + wb) + num); b <= _b;
       b = b + 1)
    if (valid((c - 1LL * wb * b) / wr, b))
      res = max(res, value((c - 1LL * wb * b) / wr, b));
  cout << res << endl;
  return 0;
}
