#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, hr, hb, wr, wb;
  while (~scanf("%I64d%I64d%I64d%I64d%I64d", &c, &hr, &hb, &wr, &wb)) {
    long long ans = 0;
    if (wr * wr >= c) {
      for (int i = 0; i * i <= c; i++) {
        if ((c - i * wr) >= 0)
          ans = max(ans, i * hr + (long long)hb * ((c - (i * wr)) / wb));
        else
          break;
      }
    } else if (wb * wb >= c) {
      for (int i = 0; i * i <= c; i++) {
        if ((c - i * wb) >= 0)
          ans = max(ans, i * hb + (long long)hr * ((c - (i * wb)) / wr));
        else
          break;
      }
    } else {
      if (hr * wb < wr * hb) {
        for (int i = 0; i * i <= c; i++) {
          if ((c - i * wr) >= 0)
            ans = max(ans, i * hr + (long long)hb * ((c - (i * wr)) / wb));
          else
            break;
        }
      } else {
        for (int i = 0; i * i <= c; i++) {
          if ((c - i * wb) >= 0)
            ans = max(ans, i * hb + (long long)hr * ((c - (i * wb)) / wr));
          else
            break;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
