#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n;
long long int c, ha, hb, wa, wb;
void sol() {
  scanf("%I64d%I64d", &(ha), &(hb));
  scanf("%I64d%I64d", &(wa), &(wb));
  long long int ans =
      max(c / wa * ha + (c % wa) / wb * hb, c / wb * hb + (c % wb) / wa * ha);
  long long int x;
  x = c / wa;
  for (long long int i = 1; i < 10000000 && i < x; i++) {
    ans = max(ans, (x - i) * ha + (c - wa * (x - i)) / wb * hb);
  }
  x = c / wb;
  for (long long int i = 1; i < 10000000 && i < x; i++) {
    ans = max(ans, (x - i) * hb + (c - wb * (x - i)) / wa * ha);
  }
  printf("%I64d\n", ans);
}
int main() {
  while (scanf("%I64d", &(c)) != EOF) sol();
  return 0;
}
