#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, ha, hb, wa, wb;
  long long f = 0, m = 0, k1 = 0, k2 = 0;
  cin >> c >> ha >> hb >> wa >> wb;
  k1 = c / wa;
  m = c - k1 * wa;
  k2 = m / wb;
  f = k1 * ha + k2 * hb;
  int l = 0;
  while (l < 10000000 && k1 > 0) {
    k1--;
    l++;
    m = c - k1 * wa;
    k2 = m / wb;
    if (f < k1 * ha + k2 * hb) f = k1 * ha + k2 * hb;
  }
  k2 = c / wb;
  m = c - k2 * wb;
  k1 = m / wa;
  l = 0;
  if (f < k1 * ha + k2 * hb) f = k1 * ha + k2 * hb;
  while (k2 > 0 && l < 10000000) {
    k2--;
    l++;
    m = c - k2 * wb;
    k1 = m / wa;
    if (f < k1 * ha + k2 * hb) f = k1 * ha + k2 * hb;
  }
  cout << f << endl;
  return 0;
}
