#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb, x, y;
int main() {
  scanf("%I64d%I64d%I64d%I64d%I64d", &c, &hr, &hb, &wr, &wb);
  long long Max = 0;
  for (long long i = 0; i <= 1000000; ++i) {
    x = i;
    if (x * wr <= c) {
      y = (c - wr * x) / wb;
      Max = max(Max, x * hr + y * hb);
    }
    y = i;
    if (y * wb <= c) {
      x = (c - wb * y) / wr;
      Max = max(Max, x * hr + y * hb);
    }
  }
  printf("%I64d", Max);
  return 0;
}
