#include <bits/stdc++.h>
using namespace std;
long long c, ha, hb, wa, wb;
long long solve() {
  long long minc = wa / wb;
  if (ha <= minc * hb) {
    return (c / wb) * hb;
  }
  if (ha >= (minc + 1) * hb) {
    return (c / wa) * ha + ((c % wa) / wb) * hb;
  }
  long long k1 = c / wa, k2 = (c % wa) / wb, av = (c % wa) % wb;
  long long ans = k1 * ha + k2 * hb;
  for (int i = (0); i < (2000000); i += (1)) {
    long long once = wa % wb;
    if (once == 0) return ans;
    long long times = ((wb - av) + once - 1) / once;
    k1 -= times;
    if (k1 < 0) {
      return ans;
    }
    k2 = (c - k1 * wa) / wb;
    ans = max(ans, k1 * ha + k2 * hb);
    av = (c - k1 * wa) % wb;
  }
  return ans;
}
int main() {
  c = ({
    int x;
    scanf("%d", &x);
    x;
  });
  ha = ({
    int x;
    scanf("%d", &x);
    x;
  });
  hb = ({
    int x;
    scanf("%d", &x);
    x;
  });
  wa = ({
    int x;
    scanf("%d", &x);
    x;
  });
  wb = ({
    int x;
    scanf("%d", &x);
    x;
  });
  if (ha < hb) {
    swap(ha, hb);
    swap(wa, wb);
  }
  long long ans = 0;
  if (wa <= wb) {
    ans = (c / wa) * ha + ((c % wa) / wb) * hb;
    cout << ans;
    return 0;
  }
  if (ha == hb) {
    ans = (c / wb) * hb;
    cout << ans;
    return 0;
  }
  ans = solve();
  swap(ha, hb);
  swap(wa, wb);
  ans = max(ans, solve());
  cout << ans;
}
