#include <bits/stdc++.h>
using namespace std;
int c;
pair<long long, long long> a;
pair<long long, long long> b;
void input() {
  cin >> c;
  cin >> a.second >> b.second;
  cin >> a.first >> b.first;
}
void solve() {
  long long ans = 0;
  if (a.first < b.first) {
    swap(a, b);
  }
  if (a.first >= 1e3) {
    for (int i = 0; i * a.first <= c; ++i) {
      ans = max(ans, i * a.second + (c - i * a.first) / b.first * b.second);
    }
  } else {
    if ((double)a.second / a.first < (double)b.second / b.first) {
      swap(a, b);
    }
    for (int i = 0; i < a.first && i * b.first <= c; ++i) {
      ans = max(ans, i * b.second + (c - i * b.first) / a.first * a.second);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
