#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb;
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  for (int x = 0; x < 1000001; x++) {
    if (x * wr > c) {
      break;
    }
    long long y = (c - x * wr) / wb;
    ans = max(ans, x * hr + y * hb);
  }
  for (int y = 0; y < 10000001; y++) {
    if (y * wb > c) {
      break;
    }
    long long x = (c - y * wb) / wr;
    ans = max(ans, x * hr + y * hb);
  }
  cout << ans << endl;
}
