#include <bits/stdc++.h>
using namespace std;
const int ITERS = 10000;
long long C, Hr, Hb, Wr, Wb;
inline long long f(long long x) { return Hb * ((C - Wr * x) / Wb) + Hr * x; }
inline long long rnd(long long m) {
  return 1 + ((long long)RAND_MAX * rand() + rand()) % m;
}
long long ann(long long EX);
int main() {
  srand(time(NULL));
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  long long a = ann(C / Wr);
  swap(Hr, Hb);
  swap(Wr, Wb);
  long long b = ann(C / Wr);
  cout << max(a, b) << endl;
}
long long ann(long long EX) {
  long long ext = EX;
  long long x = 0;
  bool jmp = true;
  while (jmp) {
    jmp = false;
    int iter = 0;
    while (ext > 0) {
      long long y;
      if (rand() % 2 == 0) {
        y = x + rnd(ext);
      } else {
        y = x - rnd(ext);
      }
      y = min(y, EX);
      y = max(y, 0ll);
      if (f(y) > f(x)) {
        ext = EX;
        x = y;
        jmp = true;
        break;
      } else {
        iter++;
      }
      if (iter > ITERS) {
        ext >>= 1;
        iter = 0;
      }
    }
  }
  return f(x);
}
