#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);
  if (wr > wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  long long ans = 0;
  if (wb >= sqrt(c)) {
    for (int i = 0; i <= c / wb; i++)
      ans = max(ans, i * hb + (c - wb * i) / wr * hr);
  } else {
    if (wr * hb < wb * hr) {
      swap(wr, wb);
      swap(hr, hb);
    }
    for (int i = 0; i < wb; i++)
      ans = max(ans, i * hr + (c - wr * i) / wb * hb);
  }
  printf("%I64d\n", ans);
  return 0;
}
