#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long arr[N];
map<long long, int> mp;
int c;
long long put(int a, int b, int e, int d) {
  long long pr2 = c % a;
  long long pr1 = c - pr2;
  long long mx = 0;
  while (pr1 >= 0 && pr2 <= c) {
    if (!mp[pr2 % e])
      mp[pr2 % e] = 1;
    else
      break;
    mx = max(mx, pr1 / a * b + pr2 / e * d);
    if (pr2 % e == 0) break;
    long long di;
    if ((e - pr2 % e) % a != 0) {
      di = (e - pr2 % e) / a + 1;
    } else
      di = (e - pr2 % e) / a;
    pr1 -= di * a, pr2 += di * a;
  }
  return mx;
}
int main() {
  int h1, h2, w1, w2;
  cin >> c >> w1 >> w2 >> h1 >> h2;
  double a = (double)w1 / h1, b = (double)w2 / h2;
  if (a >= b) {
    cout << put(h1, w1, h2, w2) << endl;
  } else
    cout << put(h2, w2, h1, w1) << endl;
  return 0;
}
