#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long res = 0;
  for (int i = 0; i <= 1000000; ++i) {
    if (wr * i <= c) {
      int j = (c - wr * i) / wb;
      res = max(res, i * hr + j * hb);
    }
    if (wb * i <= c) {
      int j = (c - wb * i) / wr;
      res = max(res, i * hb + j * hr);
    }
  }
  cout << res << endl;
  return 0;
}
