#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  if (wr > wb) {
    swap(hr, hb);
    swap(wr, wb);
  }
  if (wr == 1) {
    long long answer = 0;
    if (static_cast<long long>(hr) * wb < static_cast<long long>(hb) / wr) {
      const int t = c / wb;
      answer += static_cast<long long>(hb) * t;
      answer += static_cast<long long>(hr) * (c - t * wb);
    } else {
      answer = static_cast<long long>(hr) * c;
    }
    cout << answer << endl;
  } else {
    int x = (c / wr), t = c - x * wr;
    long long cur = static_cast<long long>(x) * hr, answer = cur;
    while (x--) {
      cur -= hr;
      t += wr;
      if (t >= wb) {
        cur += hb;
        t -= wb;
        answer = max(answer, cur);
      }
    }
    cout << answer << endl;
  }
  return 0;
}
