#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, hr, hb, wr, wb;
  long long sum = 0, ma = 0;
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) swap(wr, wb), swap(hr, hb);
  int x = max(0LL, c / ((long long)wr * wb) - 2);
  sum += x * max((long long)hr * wb, (long long)hb * wr);
  c -= x * wr * wb;
  for (int i = 0; wb * i <= c; i++)
    ma = max(ma, (long long)hb * i + (long long)hr * ((c - wb * i) / wr));
  cout << sum + ma << endl;
  return 0;
}
