#include <bits/stdc++.h>
using namespace std;
int max_can;
pair<int, int> red, blue;
int main() {
  scanf("%d%d%d%d%d", &max_can, &red.first, &blue.first, &red.second,
        &blue.second);
  long long ans = 0;
  int sq = (int)sqrt(max_can);
  if (red.second >= sq) {
    for (int cnt = 0;; ++cnt) {
      if (red.second * cnt > max_can) break;
      int can = max_can - red.second * cnt;
      ans = max(ans,
                cnt * 1ll * red.first + (can / blue.second) * 1ll * blue.first);
    }
    printf("%I64d\n", ans);
    return 0;
  } else if (blue.second >= sq) {
    for (int cnt = 0;; ++cnt) {
      if (blue.second * cnt > max_can) break;
      int can = max_can - blue.second * cnt;
      ans = max(ans,
                cnt * 1ll * blue.first + (can / red.second) * 1ll * red.first);
    }
    printf("%I64d\n", ans);
    return 0;
  } else {
    if (red.first * 1ll * blue.second < blue.first * 1ll * red.second)
      swap(red, blue);
    for (int cnt = 0; cnt <= sq; ++cnt) {
      int weight = blue.second * cnt;
      if (weight > max_can) break;
      int can = max_can - weight;
      ans = max(ans,
                blue.first * 1ll * cnt + (can / red.second) * 1ll * red.first);
    }
    printf("%I64d\n", ans);
    return 0;
  }
  return 0;
}
