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