#include <bits/stdc++.h>
using namespace std;
long long C, Hr, Hb, Wr, Wb;
long long val(long long xb) {
  if (xb * Wb > C) return 0;
  long long v = Hb * xb;
  v += ((C - Wb * xb) / Wr) * Hr;
  return v;
}
int main() {
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  long long ans = 0;
  for (long long b = 0; b <= 5000000; b++) {
    if (C - Wb * b < 0) break;
    long long r = (C - Wb * b) / Wr;
    ans = max(ans, b * Hb + r * Hr);
  }
  for (long long r = 0; r <= 5000000; r++) {
    if (C - Wr * r < 0) break;
    long long b = (C - Wr * r) / Wb;
    ans = max(ans, b * Hb + r * Hr);
  }
  cout << ans << endl;
  return 0;
}
