#include <bits/stdc++.h>
using namespace std;
unsigned long long hcf(unsigned long long n1, unsigned long long n2) {
  if (n2 != 0)
    return hcf(n2, n1 % n2);
  else
    return n1;
}
void swap(unsigned long long &n1, unsigned long long &n2) {
  unsigned long long temp = n1;
  n1 = n2;
  n2 = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  unsigned long long int C, Hr, Hb, Wr, Wb;
  cin >> C >> Hr >> Hb >> Wr >> Wb;
  if (Hr * Wb < Hb * Wr) {
    swap(Hr, Hb);
    swap(Wr, Wb);
  }
  unsigned long long lcm = (Wb * Wr) / hcf(Wr, Wb);
  unsigned long long clcm = C / lcm;
  if (clcm > 0) clcm--;
  unsigned long long mjoy = clcm * (lcm / Wr) * Hr;
  unsigned long long wleft = C - clcm * lcm;
  if (Wr < Wb) {
    swap(Hr, Hb);
    swap(Wr, Wb);
  }
  unsigned long long cr = 0;
  unsigned long long aux = mjoy;
  while (wleft >= cr * Wr) {
    unsigned long long temp = wleft - cr * Wr;
    temp = temp / Wb;
    mjoy = max(mjoy, cr * Hr + temp * Hb + aux);
    cr++;
  }
  cout << mjoy;
  return 0;
}
