#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, cr, cb, ans = -1;
  cin >> c >> hr >> hb >> cr >> cb;
  int lim = sqrt(c);
  if (cr >= lim or cb >= lim) {
    if (cb > cr) swap(cb, cr), swap(hb, hr);
    for (long long i = 0; i <= lim; i++) {
      if ((c - i * cr) >= 0) ans = max(ans, i * hr + ((c - i * cr) / cb) * hb);
    }
    cout << ans;
  } else {
    if (hb * cr > hr * cb) swap(cb, cr), swap(hr, hb);
    for (int i = 0; i <= cr; i++) {
      ans = max(ans, i * hb + ((c - i * cb) / cr) * hr);
    }
    cout << ans;
  }
  return 0;
}
