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