#include <bits/stdc++.h>
using namespace std;
long long C, Hr, Hb, Wr, Wb;
long long Calc(long long a) {
  long long all = 0;
  all += Hr * a;
  all += (C - a * Wr) / Wb * Hb;
  return all;
}
long long Solve() {
  long long Right = C / Wr;
  long long ans = Calc(Right);
  for (long long i = max(0ll, Right - 10000000); i <= Right; i++) {
    ans = max(ans, Calc(i));
  }
  return ans;
}
long long Calc2(long long a) {
  long long all = 0;
  all += Hb * a;
  all += (C - a * Wb) / Wr * Hr;
  return all;
}
long long Solve2() {
  long long Right = C / Wb;
  long long ans = Calc2(Right);
  for (long long i = max(0ll, Right - 10000000); i <= Right; i++) {
    ans = max(ans, Calc2(i));
  }
  return ans;
}
int main() {
  while (cin >> C >> Hr >> Hb >> Wr >> Wb) {
    long long ans = max(Solve(), Solve2());
    cout << ans << endl;
  }
  return 0;
}
