#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e9 + 5;
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int main() {
  long long c, hr, hb, wr, wb;
  scanf("%I64d%I64d%I64d%I64d%I64d", &c, &hr, &hb, &wr, &wb);
  long long g = (long long)wr * wb / gcd(wr, wb);
  long long ans = -9;
  if (g > 1e7 || g > c) {
    long long maxn, minn, maxp, minp;
    if (wr > wb) {
      maxn = wr;
      maxp = hr;
      minn = wb;
      minp = hb;
    } else {
      maxn = wb;
      maxp = hb;
      minn = wr;
      minp = hr;
    }
    for (int i = 0; i * maxn <= c; i++) {
      int ot = (c - i * maxn) / minn;
      long long price = i * maxp + ot * minp;
      ans = max(ans, price);
    }
  } else {
    long long a;
    long long b;
    long long ap;
    long long bp;
    if ((double)hr / wr > (double)hb / wb) {
      a = wb;
      b = wr;
      ap = hb;
      bp = hr;
    } else {
      a = wr;
      b = wb;
      ap = hr;
      bp = hb;
    }
    for (int i = 0; i * a < g; i++) {
      long long ot1 = (c - i * a) / b;
      long long price = i * ap + ot1 * bp;
      ans = max(ans, price);
    }
  }
  cout << ans << endl;
}
