#include <bits/stdc++.h>
using namespace std;
long long c, ha, hb, wa, wb;
int main() {
  long long sum = 0;
  scanf("%I64d%I64d%I64d%I64d%I64d", &c, &ha, &hb, &wa, &wb);
  long long num = ceil(sqrt(1e9)) + 1;
  long long k = c;
  long long a;
  if (wa >= num || wb >= num) {
    if (wa >= wb)
      for (int i = 0; i <= num; i++) {
        k = c;
        a = 0;
        k -= i * wa;
        if (k < 0) break;
        a += i * ha;
        a += (k / wb) * hb;
        sum = max(sum, a);
      }
    else
      for (int i = 0; i <= num; i++) {
        k = c;
        a = 0;
        k -= i * wb;
        if (k < 0) break;
        a += i * hb;
        a += (k / wa) * ha;
        sum = max(sum, a);
      }
  } else {
    if ((1.0 * ha / wa) >= (1.0 * hb / wb)) {
      for (int i = 0; i <= wa; i++) {
        k = c;
        a = 0;
        k -= i * wb;
        if (k < 0) break;
        a += i * hb;
        a += (k / wa) * ha;
        sum = max(sum, a);
      }
    } else {
      for (int i = 0; i <= wb; i++) {
        k = c;
        a = 0;
        k -= i * wa;
        if (k < 0) break;
        a += i * ha;
        a += (k / wb) * hb;
        sum = max(sum, a);
      }
    }
  }
  printf("%I64d\n", sum);
  return 0;
}
