#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
int main() {
  long long x1, y1, i, j, n, fl, k, t, m, r, x, y, z, len, tt, rr;
  scanf("%I64d%I64d%I64d%I64d%I64d", &k, &x, &y, &n, &m);
  int kk = k, xx = x, yy = y, nn = n, mm = m;
  if (m * x > n * y) {
    swap(x, y);
    swap(n, m);
  }
  fl = t = k / m;
  r = (k / m) * y;
  k -= (k / m) * m;
  x1 = t;
  y1 = r;
  for (i = 0; i <= min(10000000ll, fl); i++) {
    tt = t + (k / n);
    rr = r + (k / n) * x;
    if (rr > y1) {
      x1 = tt;
      y1 = rr;
    }
    k += m;
    t -= m;
    r -= y;
  }
  k = kk, x = xx, y = yy, n = nn, m = mm;
  if (m * x < n * y) {
    swap(x, y);
    swap(n, m);
  }
  fl = t = k / m;
  r = (k / m) * y;
  k -= (k / m) * m;
  for (i = 0; i <= min(10000000ll, fl); i++) {
    tt = t + (k / n);
    rr = r + (k / n) * x;
    if (rr > y1) {
      x1 = tt;
      y1 = rr;
    }
    k += m;
    t -= m;
    r -= y;
  }
  printf("%I64d\n", y1);
  return 0;
}
