#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 0;
long long max(long long a, long long b) { return a < b ? b : a; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int c, ha, hb, wa, wb;
int main() {
  scanf("%d%d%d%d%d", &c, &ha, &hb, &wa, &wb);
  if ((long long)ha * wb < (long long)hb * wa) swap(ha, hb), swap(wa, wb);
  int d = gcd(wa, wb);
  int z = c % d;
  long long u = c / wa;
  long long v = (c - u * wa) / wb;
  ans = u * ha + v * hb;
  if (wa == wb) {
    printf("%I64d\n", ans);
    return 0;
  }
  while (u * wa + v * wb != c - z && u * wa + v * wb <= c && u >= 0 && v >= 0) {
    ans = max(ans, u * ha + v * hb);
    u--;
    int v1 = (c - u * wa) / wb;
    if (v1 == v) {
      v++;
      u = (c - v * wb) / wa;
    } else
      v = v1;
  }
  if (u * wa + v * wb == c - z && u >= 0 && v >= 0) {
    ans = max(ans, u * ha + v * hb);
  }
  printf("%I64d\n", ans);
}
