#include <bits/stdc++.h>
using namespace std;
int main() {
  long double C, Hr, Hb, Wr, Wb;
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  ;
  long long int maxi = -1, fx, fy;
  for (long long int i = 0; i <= 1000000; i++) {
    if (i < 0) continue;
    long long int temp = (C - i * Wr) / Wb;
    if (temp < 0) continue;
    if (i * Wr + temp * Wb > C) continue;
    if (i * (long long int)Hr + temp * (long long int)Hb > maxi) {
      maxi = i * (long long int)Hr + temp * (long long int)Hb;
      fx = i;
      fy = temp;
    }
  }
  for (long long int i = 0; i <= 1000000; i++) {
    if (i < 0) continue;
    long long int temp = (C - i * Wb) / Wr;
    if (temp < 0) continue;
    if (i * Wb + temp * Wr > C) continue;
    if (i * (long long int)Hb + temp * (long long int)Hr > maxi) {
      maxi = i * (long long int)Hb + temp * (long long int)Hr;
      fy = i;
      fx = temp;
    }
  }
  cout << maxi << endl;
  return 0;
}
