#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
const long long MOD = 1000003;
const int INF = 1000000000;
const int MAXN = 200005;
const double EPS = 1e-6;
const int HASH_POW = 7;
const double PI = acos(-1.0);
using namespace std;
void my_return(int code) { exit(code); }
int main() {
  mt19937 mt_rand(time(NULL));
  int c, ha, hb, wa, wb;
  scanf("%d %d %d %d %d", &c, &ha, &hb, &wa, &wb);
  long long ans = 0;
  for (int i = 0; i <= 1000000; ++i) {
    if (i * 1ll * wa > c) break;
    int j = (c - i * wa) / wb;
    ans = max(ans, i * 1ll * ha + j * 1ll * hb);
  }
  for (int j = 0; j <= 1000000; ++j) {
    if (j * 1ll * wb > c) break;
    int i = (c - j * wb) / wa;
    ans = max(ans, i * 1ll * ha + j * 1ll * hb);
  }
  printf("%I64d\n", ans);
  my_return(0);
}
