#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000000;
int main() {
  int c, w1, v1, w2, v2;
  scanf("%d%d%d%d%d", &c, &v1, &v2, &w1, &w2);
  if ((long long)v1 * w2 < (long long)v2 * w1) swap(v1, v2), swap(w1, w2);
  int sq = sqrt(maxn + 0.5);
  long long ans = 0LL;
  if (w1 <= sq)
    for (long long i = 0; i * w2 <= c && i < w1; i++)
      ans = max(ans, i * v2 + (c - i * w2) / w1 * v1);
  else
    for (long long i = 0; i * w1 <= c; i++)
      ans = max(ans, i * v1 + (c - i * w1) / w2 * v2);
  printf("%I64d\n", ans);
}
