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