#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
long long n, m, i, j, k, l, r, s, t, d, a, b, u, ii, jj, x, y, z, h[N], hh[N];
int main() {
  cin >> m >> x >> y >> a >> b;
  for (i = m / a; i >= max(0ll, m / a - 100000); i--)
    t = max(t, i * x + (m - i * a) / b * y);
  for (i = m / b; i >= max(0ll, m / b - 100000); i--)
    t = max(t, i * y + (m - i * b) / a * x);
  cout << t << '\n';
}
