#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool mina(A &x, B y) {
  return (x > y) ? (x = y, 1) : 0;
}
template <typename A, typename B>
inline bool maxa(A &x, B y) {
  return (x < y) ? (x = y, 1) : 0;
}
int C;
long long A, B;
long long X, Y;
char S[8];
int main() {
  cin >> C >> A >> B >> X >> Y;
  long long sol = 0;
  for (int _b = (min<int>(1e7, C / X + 1)), i = (0); i < _b; ++i)
    maxa(sol, A * i + B * ((C - i * X) / Y));
  swap(A, B);
  swap(X, Y);
  for (int _b = (min<int>(1e7, C / X + 1)), i = (0); i < _b; ++i)
    maxa(sol, A * i + B * ((C - i * X) / Y));
  if (C >= 0) {
    S[0] = '%';
    S[1] = 'l';
  }
  if (A >= 0) {
    S[2] = 'l';
    S[3] = 'd';
  }
  S[4] = '\n';
  printf(S, sol);
  return 0;
}
