#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)2 * 1e9;
const long long MOD = (long long)1e9 + 7;
const long long P = 239;
const long long MAX_N = 100000;
const long long ABC = 26;
const long double pi = 3.1415926535897932384626;
const long double eps = 1e-6;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  long long c, h1, h2, w1, w2;
  cin >> c >> h1 >> h2 >> w1 >> w2;
  if (w2 > w1) {
    swap(h1, h2);
    swap(w1, w2);
  }
  if (w1 * w1 >= c) {
    long long ans = 0;
    for (long long i = 0; i * w1 <= c; i++)
      ans = max(ans, i * h1 + (c - i * w1) / w2 * h2);
    cout << ans;
  } else {
    if (h1 * w2 < h2 * w1) {
      swap(h1, h2);
      swap(w1, w2);
    }
    long long ans = 0;
    for (long long i = 0; i < w1 && i * w2 <= c; i++)
      ans = max(ans, i * h2 + (c - i * w2) / w1 * h1);
    cout << ans;
  }
  return 0;
}
