#include <bits/stdc++.h>
using namespace std;
int C, Hr, Hb, Wr, Wb;
long long Ans;
int main() {
  scanf("%i %i %i %i %i", &C, &Hr, &Hb, &Wr, &Wb);
  int BMax = C / Wb, RMax = C / Wr;
  for (int i = BMax; i >= 0 && i >= BMax - 5 * 1000 * 1000; --i) {
    long long B = 1LL * i, R = (C - 1LL * i * Wb) / Wr;
    R = max(R, 0LL);
    Ans = max(Ans, 1LL * R * Hr + 1LL * B * Hb);
  }
  for (int i = RMax; i >= 0 && i >= RMax - 5 * 1000 * 1000; --i) {
    long long R = 1LL * i, B = (C - 1LL * i * Wr) / Wb;
    B = max(B, 0LL);
    Ans = max(Ans, 1LL * R * Hr + 1LL * B * Hb);
  }
  int BMid = BMax / 2, RMid = RMax / 2;
  for (int i = max(0, BMid - 5 * 1000 * 1000);
       i <= min(BMax, BMid + 5 * 1000 * 1000); ++i) {
    long long B = 1LL * i, R = (C - 1LL * i * Wb) / Wr;
    R = max(R, 0LL);
    Ans = max(Ans, 1LL * R * Hr + 1LL * B * Hb);
  }
  for (int i = max(0, RMid - 5 * 1000 * 1000);
       i <= min(RMax, RMid + 5 * 1000 * 1000); ++i) {
    long long R = 1LL * i, B = (C - 1LL * i * Wr) / Wb;
    B = max(B, 0LL);
    Ans = max(Ans, 1LL * R * Hr + 1LL * B * Hb);
  }
  printf("%I64d\n", Ans);
}
