#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(0);
  long long tot, a, b, ta, tb;
  cin >> tot >> a >> b >> ta >> tb;
  if (ta * b <= tb * a) {
    swap(a, b), swap(ta, tb);
  }
  long long ans = 0;
  for (int i = int(0); i <= int(10000000); i++) {
    if (i * ta > tot) break;
    int cnt = (tot - i * ta) / tb;
    ans = max(ans, i * a + cnt * b);
  }
  for (int i = int(0); i <= int(10000000); i++) {
    if (i * tb > tot) break;
    int cnt = (tot - i * tb) / ta;
    ans = max(ans, i * b + cnt * a);
  }
  cout << ans << endl;
  return 0;
}
