#include <bits/stdc++.h>
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1, -2, 2, 0, 0},
    dy[] = {1, 0, 0, -1, -1, 1, 1, -1, 0, 0, -2, 2};
using namespace std;
double C, ja, jb, wa, wb;
long long eat(long long x) {
  long long rem = C - x * wa;
  long long joy = x * ja;
  joy += floor(rem / (double)wb) * jb;
  return joy;
}
int main() {
  cin >> C >> ja >> jb >> wa >> wb;
  double pa = ja / wa, push_back = jb / wb;
  long long ans = 0;
  long long left = 0, right = floor(C / (double)wa);
  int x = floor(C / wa);
  for (long long d = 0; d <= min((long long)floor(sqrt(C)), right); d++)
    ans = max(ans, eat(d));
  swap(wa, wb);
  swap(ja, jb);
  left = 0, right = floor(C / (double)wa);
  x = floor(C / wa);
  for (long long d = 0; d <= min((long long)floor(sqrt(C)), right); d++)
    ans = max(ans, eat(d));
  cout << ans << endl;
}
