#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, *A;
  int MAX, MAX2;
  cin >> N;
  A = new int[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  stable_sort(A, A + N);
  MAX = A[N - 1];
  MAX2 = A[N - 2];
  for (int i = 0; i < N; i++) {
    if (A[i] == MAX)
      cout << MAX2 << endl;
    else
      cout << MAX << endl;
  }
  delete A;
  return 0;
}
