#include <bits/stdc++.h>
using namespace std;
long long c, cr, cb, wr, wb;
int main() {
  cin >> c >> cr >> cb >> wr >> wb;
  long long ans = 0;
  for (long long i = 0; i <= 10000000; i++) {
    if (c >= i * wb) {
      long long temp = ((c - i * wb) / wr) * (cr) + i * cb;
      ans = max(ans, temp);
    }
  }
  for (long long i = 0; i <= 10000000; i++) {
    if (c >= i * wr) {
      long long temp = ((c - i * wr) / wb) * (cb) + i * cr;
      ans = max(ans, temp);
    }
  }
  printf("%lld", ans);
}
