#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int N = 22205;
int a[N];
long long c, hr, hb, wr, wb;
long long tekW;
long long tekH;
long long ost;
int main() {
  cin >> c >> hr >> hb >> wr >> wb;
  long long ans = 0;
  int i = c / wb;
  int j = c / wr;
  while (clock() < 200) {
    if (i >= 0) ans = max(ans, i * hb + ((c - i * wb) / wr) * hr);
    if (j >= 0) ans = max(ans, j * hr + ((c - j * wr) / wb) * hb);
    i--, j--;
    if (i == 0 && j == 0) break;
  }
  cout << ans;
}
