#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
long long c, hr, hb, wr, wb;
int main() {
  scanf("%d%d%d%d%d", &c, &hr, &hb, &wr, &wb);
  if (wr < wb) {
    swap(hr, hb);
    swap(wr, wb);
  }
  if (wr >= 10000) {
    int lim = c / wr;
    long long ans = 0;
    for (int i = 0; i <= lim; i++) {
      int j = (c - i * wr) / wb;
      ans = max(ans, (long long)i * hr + (long long)j * hb);
    }
    printf("%I64d\n", ans);
  } else {
    double detr = (double)hr / wr;
    double detb = (double)hb / wb;
    if (detr - detb < -eps) swap(hr, hb), swap(wr, wb);
    long long ans = 0;
    for (int i = 0; i < wr; i++) {
      if ((long long)i * wb > c) break;
      int j = (c - i * wb) / wr;
      ans = max(ans, (long long)i * hb + (long long)j * hr);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
