#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w1, w2;
  long long h1, h2;
  long long c;
  cin >> c >> h1 >> h2 >> w1 >> w2;
  long long ans = -1;
  int M = 40000;
  int x, y;
  int iteras1 = 0;
  for (y = c / w2; y >= 0; --y) {
    x = (c - w2 * y) / w1;
    ans = max(ans, h1 * x + h2 * y);
    ++iteras1;
    if (iteras1 > M) break;
  }
  int iteras2 = 0;
  for (x = c / w1; x >= 0; --x) {
    y = (c - w1 * x) / w2;
    ans = max(ans, h1 * x + h2 * y);
    ++iteras2;
    if (iteras2 > M) break;
  }
  cout << ans << "\n";
  return 0;
}
