#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned N;
  vector<unsigned> A;
  std::vector<unsigned> vec;
  cin >> N;
  A.resize(N);
  for (unsigned i = 0; i < N; ++i) {
    cin >> A[i];
  }
  unsigned max = *max_element(A.begin(), A.end());
  for (unsigned i = 0; i < N; ++i) {
    if (A[i] != max) {
      cout << max << endl;
    } else {
      A[i] = 0;
      unsigned next_max = *max_element(A.begin(), A.end());
      cout << next_max << endl;
    }
  }
}
