#include <bits/stdc++.h>
using namespace std;
const int N = 300002;
long long c, hr, hb, wr, wb;
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  for (int i = (0); i <= (int)(min(int(c / wr), 1000000)); ++i)
    ans = max(ans, i * hr + (c - i * wr) / wb * hb);
  for (int i = (0); i <= (int)(min(int(c / wb), 1000000)); ++i)
    ans = max(ans, i * hb + (c - i * wb) / wr * hr);
  cout << ans;
}
