#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long invMod(long long n) { return pwr(n, (1000000007LL) - 2); }
int main() {
  ios_base::sync_with_stdio(0);
  long long w, wr, wb, hr, hb;
  cin >> w >> hr >> hb >> wr >> wb;
  long long ans = 0;
  for (long long i = 0; i <= 1000000 && i * wr <= w; i++) {
    long long temp = i * hr + ((w - i * wr) / wb) * hb;
    ans = max(ans, temp);
  }
  for (long long i = 0; i <= 1000000 && i * wb <= w; i++) {
    long long temp = i * hb + ((w - i * wb) / wr) * hr;
    ans = max(ans, temp);
  }
  cout << ans;
  return 0;
}
