#include <bits/stdc++.h>
using namespace std;
long long n, s1, v1, s2, v2;
int main() {
  scanf("%lld%lld%lld%lld%lld", &n, &v1, &v2, &s1, &s2);
  long long ans = 0;
  long long mx = max(s1, s2);
  if (mx * mx >= n) {
    if (s1 < s2) swap(s1, s2), swap(v1, v2);
    for (long long i = 0; i * s1 <= n; i++) {
      ans = max(ans, i * v1 + (n - i * s1) / s2 * v2);
    }
  } else {
    if (v1 * s2 < v2 * s1) swap(s1, s2), swap(v1, v2);
    for (long long i = 0; i < s1 && i * s2 <= n; i++) {
      ans = max(ans, i * v2 + (n - i * s2) / s1 * v1);
    }
  }
  printf("%lld\n", ans);
}
