#include <bits/stdc++.h>
using namespace std;
long long solve(long long C, long long H_R, long long H_B, long long W_R,
                long long W_B) {
  long long ret = 0;
  if (W_R > (long long)3e4) {
    for (long long n = 0; n * W_R <= C; n++) {
      ret = max(ret, n * H_R + ((C - n * W_R) / W_B) * H_B);
    }
  } else {
    for (long long m = 0; m < W_R; m++)
      if (m * W_B <= C) {
        ret = max(ret, m * H_B + ((C - m * W_B) / W_R) * H_R);
      }
  }
  return ret;
}
int main() {
  long long C, H_R, H_B, W_R, W_B;
  scanf("%I64d%I64d%I64d%I64d%I64d", &C, &H_R, &H_B, &W_R, &W_B);
  printf("%I64d\n",
         max(solve(C, H_R, H_B, W_R, W_B), solve(C, H_B, H_R, W_B, W_R)));
  return 0;
}
