#include <bits/stdc++.h>
using namespace std;
long long w1, w2, h1, h2, c;
int solve(int n) {
  pair<int, int> p, y;
  map<int, bool> mp;
  p = {0, n};
  int mx = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push(p);
  while (!q.empty()) {
    y = q.top();
    q.pop();
    mx = max(mx, y.first);
    if (y.second - w1 >= 0 && !mp[y.second - w1])
      p = {y.first + h1, y.second - w1}, mp[y.second - w1] = true, q.push(p);
    if (y.second - w2 >= 0 && !mp[y.second - w2])
      p = {y.first + h2, y.second - w2}, mp[y.second - w2] = true, q.push(p);
  }
  return mx;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int binarysearch(int c) {
  long long l = 0, h = 10000000;
  long long score = 0;
  while (h - l > 1) {
    int m = (l + h) / 2;
    if (c - w1 * m >= 0) {
      long long y = (c - w1 * m) / w2;
      long long x = m * h1 + y * h2;
      if (x > score) {
        score = x;
        h = m;
      } else
        l = m;
    } else
      h = m;
  }
  return score;
}
int main() {
  cin >> c >> h1 >> h2 >> w1 >> w2;
  long long score = 0;
  for (int m = 0; (c - w1 * m) >= 0 && m <= 10000000; m++)
    score = max(score, h1 * m + h2 * ((c - w1 * m) / w2));
  for (int m = 0; (c - w2 * m) >= 0 && m <= 10000000; m++)
    score = max(score, h2 * m + h1 * ((c - w2 * m) / w1));
  cout << score << endl;
  return 0;
}
