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