#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, a, b, c, d;
  cin >> x >> a >> b >> c >> d;
  long long ans = 0;
  for (int i = 1; i <= 10000000; i++) {
    if (i * c > x) {
      break;
    }
    ans = max(ans, i * a + ((x - i * c) / d) * b);
    if (i * d <= x) {
      ans = max(ans, i * b + ((x - i * d) / c) * a);
    }
  }
  ans = max(ans, x / c * a);
  ans = max(ans, x / d * b);
  cout << ans << " ";
  return 0;
}
