#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int N = 22205;
int a[N];
long long c, hr, hb, wr, wb;
long long tekW;
long long tekH;
long long cnt;
long long ost;
long long f(long long q) {
  long long wQ = q * wr;
  long long hQ = q * hr;
  long long weight = wQ + ost;
  long long canCnt = weight / wb;
  long long ostH = tekH - hQ;
  long long ostW = weight - wb * canCnt;
  long long ans = ostH + (canCnt)*hb + (ostW / wr) * hr;
  return ans;
}
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  cnt = c / wr;
  tekW = cnt * wr;
  tekH = cnt * hr;
  ost = c - tekW;
  long long ans = tekH;
  long long l = 0;
  long long r = cnt;
  for (long long v = l; v <= r; v++) {
    ans = max(ans, f(v));
    ans = max(ans, f(r - (v - l)));
    if (clock() >= 500) break;
  }
  cout << ans;
}
