#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long sq = sqrt(c), ans = 0;
  if (wb > sq) {
    for (long long i = 0; i <= (c / wb); i++)
      ans = max(ans, hb * i + hr * ((c - i * wb) / wr));
  } else if (wr > sq) {
    for (long long i = 0; i <= (c / wr); i++)
      ans = max(ans, hr * i + hb * ((c - i * wr) / wb));
  } else {
    for (long long i = 0; i <= wr; i++)
      ans = max(ans, hb * i + hr * ((c - i * wb) / wr));
    for (long long i = 0; i <= wb; i++)
      ans = max(ans, hr * i + hb * ((c - i * wr) / wb));
  }
  cout << ans << "\n";
}
