#include <bits/stdc++.h>
using namespace std;
int INT_MAX_VAL = (int)1e20;
int INT_MIN_VAL = (int)-1e20;
long long LONG_MAX_VAL = (long long)1e20;
long long LONG_MIN_VAL = (long long)-1e20;
long long C, Hr, Hb, Wr, Wb;
long long func(long long x) {
  long long y = (C - Wb * x) / Wr;
  return Hb * x + Hr * y;
}
long long solve() {
  long long l = 0;
  long long r = min(C / Wb, 10000000LL);
  long long res = 0;
  for (long long i = 0; i <= r; ++i) {
    res = max(res, func(i));
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  long long res1 = solve();
  swap(Hr, Hb);
  swap(Wr, Wb);
  long long res2 = solve();
  cout << max(res1, res2) << '\n';
  return 0;
}
