#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
long long c, hr, hb, wr, wb;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> c >> hr >> hb >> wr >> wb;
  long long res = 0;
  pair<long long, long long> P, A, B;
  if (hb * wr > hr * wb) {
    P.first = hb;
    P.second = wb;
  } else {
    P.first = hr;
    P.second = wr;
  }
  if (wr > wb) {
    A.first = hr;
    A.second = wr;
    B.first = hb;
    B.second = wb;
  } else {
    A.first = hb;
    A.second = wb;
    B.first = hr;
    B.second = wr;
  }
  long long t = c - wr * wb;
  long long ret = 0;
  if (t >= 0) {
    ret = (t / P.second) * P.first;
    c -= (t / P.second) * P.second;
  }
  for (int i = 0; i <= c / A.second; i++) {
    res = max(res, i * A.first + (c - i * A.second) / B.second * B.first);
  }
  cout << ret + res << endl;
  return 0;
}
