#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int c, hr, hb, wr, wb, ans = 0;
  cin >> c >> hr >> hb >> wr >> wb;
  for (long long int k = 1; k <= 2; k++) {
    for (long long int i = 0; i <= 1000000; i++) {
      if (i * wr > c) break;
      ans = max(ans, i * hr + hb * ((c - i * wr) / wb));
    }
    swap(hr, hb);
    swap(wr, wb);
  }
  cout << ans << endl;
}
