#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb;
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  long long sq = sqrt(c), mx = 0;
  for (int i = 0; i <= sq; i++) {
    if (i * wr <= c) mx = max(mx, i * hr + ((c - i * wr) / wb) * hb);
    if (i * wb <= c) mx = max(mx, i * hb + ((c - i * wb) / wr) * hr);
  }
  cout << mx << endl;
}
