#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb;
int main() {
  while (scanf("%lld%lld%lld%lld%lld", &c, &hr, &hb, &wr, &wb) == 5) {
    long long ans = 0;
    for (long long i = 0; i * wr <= c && i <= sqrt(c) + 1; i++) {
      long long tmp = i * hr + (c - i * wr) / wb * hb;
      ans = max(ans, tmp);
    }
    for (long long i = 0; i * wb <= c && i <= sqrt(c) + 1; i++) {
      long long tmp = i * hb + (c - i * wb) / wr * hr;
      ans = max(ans, tmp);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
