#include <bits/stdc++.h>
using namespace std;
long long calc(long long a, long long c, long long h1, long long h2,
               long long w1, long long w2) {
  if (c - a * w1 < 0) return -1;
  long long t = (c - a * w1) / w2;
  return (a * h1 + t * h2);
}
int main() {
  int c, w1, w2, h1, h2;
  cin >> c >> h1 >> h2 >> w1 >> w2;
  long long m = 0;
  if (w1 * w1 >= c) {
    for (int i = 0; i * i <= c; i++) m = max(m, calc(i, c, h1, h2, w1, w2));
    cout << m;
    return 0;
  }
  if (w2 * w2 >= c) {
    for (int i = 0; i * i <= c; i++) m = max(m, calc(i, c, h2, h1, w2, w1));
    cout << m;
    return 0;
  }
  if (h1 / w1 > h2 / w2) {
    swap(h1, h2);
    swap(w1, w2);
  }
  for (int i = 0; i <= 10000000; i++) {
    m = max(m, calc(i, c, h2, h1, w2, w1));
  }
  for (int i = 0; i <= 10000000; i++) {
    m = max(m, calc(i, c, h1, h2, w1, w2));
  }
  cout << m;
  return 0;
}
