#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int interval = 25;
int _10_8 = 100000000;
int _10_7 = 10000000;
long long maxJoy;
long long C;
void tryIt(long long wr, long long wb, long long jr, long long jb,
           long long int a, long long int b) {
  if (a < 0) a = 0;
  if (b > C) b = C;
  for (long long int r = a; r <= b; r++) {
    long long int diff = C - wr * r;
    if (diff < 0) return;
    long long int bb = diff / wb;
    long long joy = jr * r + jb * bb;
    if (joy > maxJoy) maxJoy = joy;
  }
}
void newApproach(long long wr, long long wb, long long jr, long long jb) {
  vector<long long> vJoy;
  for (int r = _10_7; r <= C; r += interval) {
    int diff = C - wr * r;
    if (diff < 0) break;
    int b = diff / wb;
    long long joy = jr * r + jb * b;
    vJoy.push_back(joy);
  }
  long long maxv = 0;
  vector<int> indexv;
  int cnt = 0;
  for (int i = 0; i < vJoy.size(); i++) {
    if (vJoy[i] > maxv) {
      maxv = vJoy[i];
      indexv.clear();
      indexv.push_back(_10_7 + i * interval);
      cnt = 1;
    } else if (vJoy[i] == maxv) {
      cnt++;
      indexv.push_back(_10_7 + i * interval);
    }
  }
  random_shuffle(indexv.begin(), indexv.end());
  for (int i = 0; i < 100 && i < indexv.size(); i++) {
    tryIt(wr, wb, jr, jb, indexv[i] - 500, indexv[i] + 500);
  }
}
int main() {
  int test, cases = 1;
  long long jr, jb, wr, wb;
  cin >> C >> jr >> jb >> wr >> wb;
  if (wr == wb) {
    long long maxJ = jr;
    if (jb > maxJ) maxJ = jb;
    long long int can = C / wr;
    cout << (can * maxJ) << endl;
    return 0;
  }
  if (jr == jb) {
    long long minW = wr;
    if (minW > wb) minW = wb;
    long long can = C / minW;
    cout << (can * jr) << endl;
    return 0;
  }
  maxJoy = 0;
  if (C <= _10_8) {
    for (int r = 0; r <= C; r++) {
      int diff = C - wr * r;
      if (diff < 0) break;
      int b = diff / wb;
      long long joy = jr * r + jb * b;
      if (joy > maxJoy) maxJoy = joy;
    }
    cout << maxJoy << endl;
    return 0;
  }
  tryIt(wr, wb, jr, jb, 0, _10_7);
  tryIt(wb, wr, jb, jr, 0, _10_7);
  cout << maxJoy << endl;
  return 0;
}
