#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  long long g = gcd(wr, wb);
  long long lcm = wr * wb / g;
  long long add = max(wb * hr / g, wr * hb / g);
  long long cnt = c / lcm;
  long long ans = 0;
  if (cnt > 1) {
    ans = (cnt - 1) * add;
    c = c % lcm + lcm;
  }
  long long i1 = c / wr;
  long long i2 = c / wb;
  long long res = 0;
  if (i1 < i2) {
    for (long long i = 0; i <= i1; i++) {
      long long tmp = hr * i + (c - wr * i) / wb * hb;
      res = max(res, tmp);
    }
  } else {
    for (long long i = 0; i <= i2; i++) {
      long long tmp = hb * i + (c - wb * i) / wr * hr;
      res = max(res, tmp);
    }
  }
  cout << ans + res << endl;
  return 0;
}
