#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
int main() {
  long long c, hr, wr, hb, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  for (long long i = 0; wb * i <= c && i <= 10000000; i++) {
    ans = max(ans, i * hb + (c - i * wb) / wr * hr);
  }
  for (long long i = 0; wr * i <= c && i <= 10000000; i++) {
    ans = max(ans, i * hr + (c - i * wr) / wb * hb);
  }
  printf("%lld\n", ans);
}
