#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int C, h1, h2, w1, w2;
  scanf("%I64d %I64d %I64d %I64d %I64d", &C, &h1, &h2, &w1, &w2);
  long long int ret = 0;
  for (int i = 0; i < 1000005; i++) {
    long long int o1 = w1 * (long long int)i;
    if (o1 <= C) {
      long long int c2 = (C - o1) / w2;
      ret = max(ret, h1 * (long long int)i + h2 * c2);
    }
    long long int o2 = w2 * (long long int)i;
    if (o2 <= C) {
      long long int c1 = (C - o2) / w1;
      ret = max(ret, h1 * c1 + h2 * (long long int)i);
    }
  }
  printf("%I64d\n", ret);
  return 0;
}
