#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int max = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > A[i - 1]) max = A[i];
  }
  bool ismax[N];
  for (int i = 0; i < N; i++) {
    if (A[i] == max)
      ismax[i] = 1;
    else
      ismax[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    if (ismax[i] != 1) {
      cout << max << endl;
      continue;
    }
    int submax;
    for (int j = 0; j < N; j++) {
      if (j == i) continue;
      if (j == i + 1) {
        if (A[j] > A[j - 2]) submax = A[j];
      } else {
        if (A[j] > A[j - 1]) submax = A[j];
      }
    }
    cout << submax << endl;
  }
}
