#include <bits/stdc++.h>
using namespace std;
const int MX = 110001;
int N, k, M;
long long gcd(long long a, long long b) {
  while (a && b) {
    if (a >= b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
void solve() {
  long long C, Hr, Hb, Wr, Wb;
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  long long lcm = (Wr * Wb) / gcd(Wr, Wb), joyRed = lcm / Wr * Hr,
            joyBlue = lcm / Wb * Hb;
  long long How = C / lcm;
  if (How) --How;
  long long ans = How * max(joyBlue, joyRed);
  C -= How * lcm;
  if (Wr < Wb) {
    swap(Wr, Wb);
    swap(Hr, Hb);
  }
  long long cur = 0;
  for (long long j = 0; j * Wr <= C; j++) {
    long long rem = C - j * Wr;
    long long have = rem / Wb * Hb;
    have += j * Hr;
    cur = max(cur, have);
  }
  cout << cur + ans << '\n';
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
