#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
const int INF = 1000000000, mod = 1000000007;
const long long LLINF = 1000000000000000000ll;
const int mx = 1e6;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  long long res = 0;
  if (c / wb <= 5e7) {
    long long lstW = 0, lstH = 0;
    for (long long i = 0; lstW <= c; i++) {
      res = max(res, lstH + (c - lstW) / wr * hr);
      lstW += wb;
      lstH += hb;
    }
    cout << res << '\n';
    return 0;
  }
  vector<long long> s;
  s.push_back(1);
  s.push_back(c);
  s.push_back(500000000);
  s.push_back(c / 2);
  s.push_back(c / 4);
  s.push_back(c / 8);
  s.push_back(c / 6);
  s.push_back(c * 3 / 2);
  s.push_back(c * 5 / 2);
  s.push_back(c * 7 / 2);
  s.push_back(c * 3 / 4);
  s.push_back(c * 5 / 4);
  s.push_back(c * 7 / 4);
  s.push_back(c * 3 / 8);
  s.push_back(c * 5 / 8);
  s.push_back(c * 7 / 8);
  s.push_back(c * 3 / 6);
  s.push_back(c * 5 / 6);
  s.push_back(c * 7 / 6);
  s.push_back(c * 3 / 6);
  s.push_back(c * 5 / 6);
  s.push_back(c * 7 / 6);
  for (int i = 0; i < s.size(); ++i) {
    for (long long l = max(0ll, s[i] - mx), r = min(c, s[i] + mx); l <= r;
         ++l) {
      if (l * wr <= c) res = max(res, l * hr + (c - l * wr) / wb * hb);
      if (l * wb <= c) res = max(res, l * hb + (c - l * wb) / wr * hr);
    }
  }
  cout << res << '\n';
  return 0;
}
