#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const int mod = 1000000007;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long c, hr, hb, wr, wb;
  while (cin >> c >> hr >> hb >> wr >> wb) {
    long long ans = 0;
    if (wr * wr >= c) {
      for (long long i = 0; i <= c / wr; ++i) {
        long long p = c - i * wr;
        long long s = i * hr + p / wb * hb;
        ans = max(ans, s);
      }
    } else if (wb * wb >= c) {
      for (long long i = 0; i <= c / wb; ++i) {
        long long p = c - i * wb;
        long long s = i * hb + p / wr * hr;
        ans = max(ans, s);
      }
    } else if (hr * wb >= wr * hb) {
      for (long long i = 0; i <= wr; ++i) {
        ans = max(ans, i * hb + (c - i * wb) / wr * hr);
      }
    } else {
      for (long long i = 0; i <= wb; ++i) {
        ans = max(ans, i * hr + (c - i * wr) / wb * hb);
      }
    }
    cout << ans << endl;
  }
}
