#include <bits/stdc++.h>
using namespace std;
long long H[2], W[2];
int main() {
  long long C;
  while (cin >> C >> H[0] >> H[1] >> W[0] >> W[1]) {
    long long ans = 0;
    for (long long i = 0; i <= 100000; i++)
      for (int j = 0; j < 2; j++)
        if (i * W[j] <= C) {
          long long ok = i * H[j] + (C - i * W[j]) / W[j ^ 1] * H[j ^ 1];
          ans = ans > ok ? ans : ok;
        }
    cout << ans << endl;
  }
  return 0;
}
