#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int c, hr, hb, wr, wb;
  cin >> c >> hr >> hb >> wr >> wb;
  long long int ret = 0, ret1 = 0;
  int cnt = 0;
  for (long long int i = 0; i <= (c / wr); i++) {
    long long int r = i * wr;
    long long int l = c - r;
    long long int b = l / wb;
    ret1 = i * hr + b * hb;
    ret = max(ret, ret1);
    cnt++;
    if (cnt > 1e7) break;
  }
  cnt = 0;
  for (long long int i = 0; i <= (c / wb); i++) {
    long long int r = i * wb;
    long long int l = c - r;
    long long int b = l / wr;
    ret1 = i * hb + b * hr;
    ret = max(ret, ret1);
    cnt++;
    if (cnt > 1e7) break;
  }
  cout << ret << endl;
  return 0;
}
