#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int C, Pr, Ps, Wr, Ws;
  cin >> C >> Pr >> Ps >> Wr >> Ws;
  if (max(Wr, Ws) >= sqrt(C)) {
    if (Ws > Wr) {
      swap(Pr, Ps);
      swap(Wr, Ws);
    }
    long long int t = C / Wr;
    long long int max;
    bool flag = false;
    long long int prevy = -1;
    long long int temp = 0;
    for (long long int x = 0; x <= t; ++x) {
      long long int y = (C - temp) / Ws;
      temp += Wr;
      long long int value = x * Pr + y * Ps;
      if (flag && max < value) {
        max = value;
      } else if (!flag) {
        flag = true;
        max = value;
      }
    }
    cout << max << endl;
  } else {
    if (Ps * Wr > Pr * Ws) {
      swap(Pr, Ps);
      swap(Wr, Ws);
    }
    bool flag = false;
    long long int max;
    for (long long int nb = 0; nb < sqrt(C); ++nb) {
      long long int nr = (C - nb * Ws) / Wr;
      long long int value = nr * Pr + nb * Ps;
      if (flag && max < value) {
        max = value;
      } else if (!flag) {
        flag = true;
        max = value;
      }
    }
    cout << max << endl;
  }
  return 0;
}
