#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1000000000")
int main() {
  ios_base::sync_with_stdio(0);
  long long s, a, b, c, d, res = 0;
  cin >> s >> a >> b >> c >> d;
  for (long long i = 0; i <= 1000000; ++i) {
    if (c * i > s) break;
    res = max(res, i * a + (s - c * i) / d * b);
  }
  swap(a, b);
  swap(c, d);
  for (long long i = 0; i <= 1000000; ++i) {
    if (c * i > s) break;
    res = max(res, i * a + (s - c * i) / d * b);
  }
  cout << res << endl;
  return 0;
}
