#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool uax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long C, h1, h2, w1, w2;
int main() {
  ios::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
  cin >> C >> h1 >> h2 >> w1 >> w2;
  if (w1 < w2) swap(w1, w2), swap(h1, h2);
  long long ans = 0;
  if (w1 >= 1000) {
    for (long long a = 0; a * w1 <= C; ++a) {
      long long b = (C - a * w1) / w2;
      uax(ans, a * h1 + b * h2);
    }
  } else {
    for (long long a = 0; a <= 10000 && a * w1 <= C; ++a) {
      long long b = (C - a * w1) / w2;
      uax(ans, a * h1 + b * h2);
    }
    for (long long b = 0; b <= 10000 && b * w2 <= C; ++b) {
      long long a = (C - b * w2) / w1;
      uax(ans, a * h1 + b * h2);
    }
  }
  cout << ans << '\n';
  return 0;
}
