#include <bits/stdc++.h>
using namespace std;
long long C, Hr, Hb, Wr, Wb;
long long blues(long long reds) { return (C - (Wr * reds)) / Wb; }
long long reds(long long blues) { return (C - (Wb * blues)) / Wr; }
int main(int argc, char* argv[]) {
  scanf("%I64d %I64d %I64d %I64d %I64d", &C, &Hr, &Hb, &Wr, &Wb);
  long long rt = sqrt(C);
  long long ans = 0;
  for (int blue = 0; blue <= rt; blue++) {
    long long red = reds(blue);
    if (red < 0) {
      continue;
    }
    long long val = Wr * red + Wb * blue <= C ? Hr * red + Hb * blue : -1e18;
    ans = max(ans, val);
  }
  for (int red = 0; red <= rt; red++) {
    long long blue = blues(red);
    if (blue < 0) {
      continue;
    }
    long long val = Wr * red + Wb * blue <= C ? Hr * red + Hb * blue : -1e18;
    ans = max(ans, val);
  }
  printf("%I64d\n", ans);
  return 0;
}
