#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
const double eps = 1e-7;
long long ans;
long long C, h1, h2, w1, w2;
long long calc(long long x) {
  long long res = x * h1;
  long long other = C - x * w1;
  return res + other / w2 * h2;
}
long long calc1(long long x) {
  long long res = x * h2;
  long long other = C - x * w2;
  return res + other / w1 * h1;
}
int main() {
  cin >> C >> h1 >> h2 >> w1 >> w2;
  for (int i = 0; i <= min(C / w1, 1000000LL); i++) ans = max(ans, calc(i));
  for (int i = 0; i <= min(C / w2, 1000000LL); i++) ans = max(ans, calc1(i));
  cout << ans << endl;
  return 0;
}
