#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  long long c, vr, vb, wr, wb;
  cin >> c >> vr >> vb >> wr >> wb;
  long long G = lcm(wr, wb);
  long long t = c / G - 1;
  t = t < 0 ? 0 : t;
  long long tr = G / wr * vr * t;
  long long tb = G / wb * vb * t;
  long long ans1 = max(tr, tb);
  if (wr < wb) swap(wr, wb), swap(vr, vb);
  long long remain = G < c ? c % G + G : c;
  long long ans2 = -0x3f3f3f3f;
  for (long long num_r = 0; num_r <= remain / wr; ++num_r) {
    long long num_b = (remain - num_r * wr) / wb;
    ans2 = max(ans2, num_r * vr + num_b * vb);
  }
  cout << ans1 + ans2;
}
