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