#include <bits/stdc++.h>
using namespace std;
long long C, hr, hb, wr, wb;
long long f(long long x) { return hr * x + (C - wr * x) / wb * hb; }
int main() {
  while (cin >> C >> hr >> hb >> wr >> wb) {
    long long res = 0;
    for (int turn = 0, _a = (2); turn < _a; turn++) {
      long long left = 0, right = C / wr;
      res = max(res, max(f(left), f(right)));
      for (int turn = 0, _a = (10000); turn < _a; turn++) {
        long long x1 = (left + left + right) / 3;
        long long x2 = (left + right + right) / 3;
        long long y1 = f(x1), y2 = f(x2);
        res = max(res, max(y1, y2));
        if (y1 > y2)
          right = x2;
        else
          left = x1;
      }
      for (int x = 0, _a = (min(10000000LL, C / wr)); x < _a; x++)
        res = max(res, f(x));
      for (int x = (C / wr), _b = (max(0LL, C / wr - 10000000LL)); x >= _b; x--)
        res = max(res, f(x));
      swap(hr, hb);
      swap(wr, wb);
    }
    cout << res << endl;
  }
  return 0;
}
