#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
  s << '{';
  for (int i = 0; i < v.size(); ++i) s << (i ? "," : "") << v[i];
  return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
void swap(long long* a, long long* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
long long C, Hr, Hb, Wr, Wb;
int main() {
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  long long ir = C / Wr;
  long long best = 0;
  int times = 0;
  while (true) {
    long long ib = (C - ir * Wr) / Wb;
    if (ir < 0) break;
    if (ib < 0) break;
    long long obj = ir * Hr + ib * Hb;
    if (obj > best) best = obj;
    if (times == 1000000) break;
    ir--;
    times++;
  }
  times = 0;
  long long ib = C / Wb;
  while (true) {
    long long ir = (C - ib * Wb) / Wr;
    if (ir < 0) break;
    if (ib < 0) break;
    long long obj = ir * Hr + ib * Hb;
    if (obj > best) best = obj;
    if (times == 1000000) break;
    ib--;
    times++;
  }
  cout << best << endl;
}
