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