#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb;
int main() {
  ios::sync_with_stdio(false);
  cin >> c >> hr >> hb >> wr >> wb;
  int b, r;
  if (wr * hb > hr * wb) {
    b = (c / wb);
    r = (c - (wb * b)) / wr;
    long long s = b * hb + r * hr;
    if (wb * wb > c) {
      while (b > 0 && b * wb + r * wr != c) {
        b = b - 1;
        r = (c - (wb * b)) / wr;
        s = max(s, b * hb + r * hr);
      }
    } else if (wr * wr > c) {
      while ((r + 1) * wr <= c) {
        r++;
        b = (c - (wr * r)) / wb;
        s = max(s, b * hb + r * hr);
      }
    } else {
      while (r * r <= c) {
        r++;
        b = (c - (wr * r)) / wb;
        s = max(s, b * hb + r * hr);
      }
    }
    cout << s;
  } else {
    r = c / wr;
    b = (c - r * wr) / wb;
    long long s = b * hb + r * hr;
    if (wr * wr > c) {
      while (r > 0 && b * wb + r * wr != c) {
        r = r - 1;
        b = (c - (wr * r)) / wb;
        s = max(s, b * hb + r * hr);
      }
    } else if (wb * wb > c) {
      while ((b + 1) * wb <= c) {
        b++;
        r = (c - (wb * b)) / wr;
        s = max(s, b * hb + r * hr);
      }
    } else {
      while (b * b <= c) {
        b++;
        r = (c - (wb * b)) / wr;
        s = max(s, b * hb + r * hr);
      }
    }
    cout << s;
  }
  return 0;
}
