#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> B(N, 0);
  int BB = -1;
  for (int i = 0; i < N; i++) {
    BB = max(BB, A[i]);
    B[i] = BB;
  }
  vector<int> C(N, 0);
  int CC = -1;
  for (int i = N - 1; i >= 0; i--) {
    CC = max(CC, A[i]);
    C[i] = CC;
  }
  for (int i = 0; i < N; i++) {
    if (i == 0)
      cout << C[1] << endl;
    else if (i == N - 1)
      cout << B[N - 1] << endl;
    else
      cout << max(B[i - 1], C[i + 1]) << endl;
  }
  return 0;
}
