#include <bits/stdc++.h>
using namespace std;
const int N = 2e7 + 7;
long long mn = (long long)(1e18 + 7), mx = -(long long)(1e18 + 7);
long long n, m, k, s, q, t;
long long a, b, c, d, e;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> a >> b >> c >> d;
  for (int i = 0; i <= N; i++) {
    if (i * c <= n) mx = max(mx, i * a + ((n - i * c) / d * b));
    if (i * d <= n) mx = max(mx, i * b + ((n - i * d) / c * a));
  }
  cout << mx;
}
