#include <bits/stdc++.h>
using namespace std;
int c, hi, hb, wi, wb;
inline long long f(int x) {
  long long k1 = x;
  long long k2 = 1ll * (0ll + c - 1ll * x * wi) / wb;
  return k1 * hi + k2 * hb;
}
int main() {
  cin >> c >> hi >> hb >> wi >> wb;
  int kek1 = c / wi;
  int l = 0;
  int r = kek1;
  long long ans = 0;
  ans = max(ans, f(0));
  ans = max(ans, f(kek1));
  for (int i = 0; i <= 10000000; ++i)
    if (i <= kek1) ans = max(ans, f(i));
  while (r - l > 1) {
    int m = (r - l + 1) / 3;
    int k1 = l + m;
    int k2 = r - m;
    if (f(k1) > f(k2))
      r = k2;
    else
      l = k1;
  }
  for (int i = l - 9000000; i <= r + 9000000; ++i)
    if (i >= 0 && i <= kek1) ans = max(ans, f(i));
  swap(wi, wb);
  swap(hi, hb);
  kek1 = c / wi;
  l = 0;
  r = kek1;
  for (int i = 0; i <= 10000000; ++i)
    if (i <= kek1) ans = max(ans, f(i));
  while (r - l > 1) {
    int m = (r - l + 1) / 3;
    int k1 = l + m;
    int k2 = r - m;
    if (f(k1) > f(k2))
      r = k2;
    else
      l = k1;
  }
  for (int i = l - 9000000; i <= r + 9000000; ++i)
    if (i >= 0 && i <= kek1) ans = max(ans, f(i));
  ans = max(ans, f(0));
  ans = max(ans, f(kek1));
  cout << ans;
}
