#include <bits/stdc++.h>
using namespace std;
int main() {
  long long C, u1, u2, c1, c2;
  cin >> C >> u1 >> u2 >> c1 >> c2;
  long long mx = 0;
  for (long long i = 0, j; i <= 10000000LL; ++i) {
    if (i * c1 <= C) mx = max(mx, i * u1 + (C - i * c1) / c2 * u2);
    j = C - i;
    if (j * c2 <= C && C >= i) mx = max(mx, j * u2 + (C - j * c2) / c1 * u1);
  }
  for (long long i = 0, j; i <= 10000000LL; ++i) {
    if (i * c2 <= C) mx = max(mx, i * u2 + (C - i * c2) / c1 * u1);
    j = C - i;
    if (j * c1 <= C && C >= i) mx = max(mx, j * u1 + (C - j * c1) / c2 * u2);
  }
  cout << mx;
  return 0;
}
