#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, s1, v1, s2, v2;
  long long cur, m = 0;
  cin >> n >> v1 >> v2 >> s1 >> s2;
  if (s1 > s2) {
    swap(s1, s2);
    swap(v1, v2);
  }
  if (s2 > sqrt(n)) {
    for (long long i = 0; i * s2 <= n; i++) {
      cur = i * v2 + (n - i * s2) / s1 * v1;
      m = max(m, cur);
    }
  } else {
    if (v2 * s1 < v1 * s2) {
      swap(s1, s2);
      swap(v1, v2);
    }
    for (long long i = 0; i <= s2 && (n - i * s1 >= 0); i++) {
      cur = i * v1 + (n - i * s1) / s2 * v2;
      m = max(m, cur);
    }
  }
  cout << m << "\n";
  return 0;
}
