#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0LL) return a;
  return gcd(b, a % b);
}
int main(void) {
  long long c, hr, hb, wr, wb;
  scanf("%lld%lld%lld%lld%lld", &c, &hr, &hb, &wr, &wb);
  long long g = (wr * wb) / gcd(wr, wb);
  long long col;
  if (c / g == 0LL)
    col = 0LL;
  else
    col = c / g - 1LL;
  long long answer1 = col * max(((g / wr) * hr), ((g / wb) * hb));
  c = (c - col * g);
  if (wr < wb) {
    swap(wr, wb);
    swap(hr, hb);
  }
  long long answer2 = 0LL;
  for (long long i = 0LL; i * wr <= c; i++) {
    answer2 = max(answer2, i * hr + ((c - i * wr) / wb) * hb);
  }
  printf("%lld", answer1 + answer2);
  return 0;
}
