#include <bits/stdc++.h>
using namespace std;
long long w[2];
long long v[2];
long long C;
int main() {
  while (cin >> C >> v[0] >> v[1] >> w[0] >> w[1]) {
    if (w[0] < w[1]) {
      swap(v[0], v[1]);
      swap(w[0], w[1]);
    }
    if (C / w[0] < 200000) {
      long long ans = 0;
      for (int i = 0; w[0] * i <= C; i++) {
        long long Cp = C - w[0] * i;
        long long val = i * v[0] + (Cp / w[1]) * v[1];
        ans = max(val, ans);
      }
      cout << ans << "\n";
    } else {
      if (v[0] * w[1] < v[1] * w[0]) {
        swap(v[0], v[1]);
        swap(w[0], w[1]);
      }
      long long vb = v[0] * 200000;
      long long wb = w[0] * 200000;
      long long val = (C / wb) * vb;
      long long ans = 0;
      C -= (C / wb) * wb;
      for (int i = 0; i <= 200000 && i * w[0] <= C; i++) {
        long long Cp = C - w[0] * i;
        long long lval = i * v[0] + (Cp / w[1]) * v[1];
        ans = max(lval, ans);
      }
      cout << ans + val << "\n";
    }
  }
  return 0;
}
