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