#include <bits/stdc++.h>
using namespace std;
long long N;
long long A[2000005];
long long L[2000005];
long long R[2000005];
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  L[0] = A[0];
  for (long long i = 1; i <= N; i++) {
    L[i] = max(L[i - 1], A[i]);
  }
  L[N - 1] = A[N - 1];
  for (long long i = N - 2; i >= 0; i--) {
    R[i] = max(R[i + 1], A[i]);
  }
  for (long long i = 0; i < N; i++) {
    if (i == 0) {
      cout << R[i + 1] << endl;
    } else if (i == N - 1) {
      cout << L[i - 1] << endl;
    } else {
      cout << max(L[i - 1], R[i + 1]) << endl;
    }
  }
}
