#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> as(n);
  for (auto &a : as) {
    cin >> a;
  }
  int64_t fst = 0, snd = -1;
  for (int64_t i = 0; i < n; i++) {
    if (as[fst] < as[i]) {
      snd = fst;
      fst = i;
    } else if ((snd == -1) || (as[snd] < as[i])) {
      snd = i;
    }
  }
  for (int64_t i = 0; i < n; i++) {
    if (i == fst) {
      cout << as[snd] << endl;
    } else {
      cout << as[fst] << endl;
    }
  }
  return 0;
}
