#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long c, h1, h2, w1, w2;
  cin >> c >> h1 >> h2 >> w1 >> w2;
  long long ans = 0;
  for (int i = 0; i <= 1000000; ++i) {
    if (i * w1 > c) break;
    ans = max(ans, h1 * i + (c - w1 * i) / w2 * h2);
  }
  for (int i = 0; i <= 1000000; ++i) {
    if (i * w2 > c) break;
    ans = max(ans, h2 * i + (c - w2 * i) / w1 * h1);
  }
  cout << ans;
  ;
  return 0;
}
