#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  int M = B[N - 1];
  int m = M;
  for (int i = N - 1; i >= 0; i--) {
    if (B[i] != M) {
      m = B[i];
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] != M)
      cout << M << endl;
    else
      cout << m << endl;
  }
}
