#include <bits/stdc++.h>
using namespace std;
long long c, a, b, x, y, mx, i;
int main() {
  cin >> c >> a >> b >> x >> y;
  if (y > x) {
    swap(x, y);
    swap(a, b);
  }
  if (x > (long long)1e5 or y > (long long)1e5) {
    for (i = 0; i <= (long long)1e5; i++) {
      if (x * i > c) break;
      mx = max(mx, i * a + (c - i * x) / y * b);
    }
  } else {
    if ((double)a / x < (double)b / y) {
      swap(a, b);
      swap(x, y);
    }
    for (i = 0; i <= (long long)1e5; i++) {
      if (y * i > c) break;
      mx = max(mx, i * b + (c - i * y) / x * a);
    }
  }
  cout << mx;
}
