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