#include <bits/stdc++.h>
using namespace std;
long long gcd(long long da, long long xiao) {
  long long temp;
  while (xiao != 0) {
    temp = da % xiao;
    da = xiao;
    xiao = temp;
  }
  return da;
}
int main() {
  int T;
  long long N, S1, V1, S2, V2;
  scanf("%I64d%I64d%I64d%I64d%I64d", &N, &V1, &V2, &S1, &S2);
  long long tmp = S1 * S2 / gcd(S1, S2);
  long long res;
  long long tt = N / tmp;
  N = N % tmp;
  if (tt) {
    tt--;
    N += tmp;
  }
  res = max((tt) * (tmp / S1) * V1, (tt) * (tmp / S2) * V2);
  long long res2 = 0;
  if (S2 > S1) {
    long long t;
    t = S1;
    S1 = S2;
    S2 = t;
    t = V1;
    V1 = V2;
    V2 = t;
  }
  for (int i = 0; i <= N / S1; i++) {
    if (res2 < i * V1 + (N - i * S1) / S2 * V2)
      res2 = i * V1 + (N - i * S1) / S2 * V2;
  }
  res += res2;
  printf("%I64d\n", res);
}
