#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> memo1(n);
  vector<int> memo2(n);
  memo1[0] = a[0];
  int maxa = a[0];
  for (int i = 1; i < n; i++) {
    memo1[i] = max(maxa, a[i]);
  }
  memo2[n - 1] = a[n - 1];
  maxa = a[n - 1];
  for (int i = 1; i < n; i++) {
    memo2[n - 1 - i] = max(maxa, a[n - 1 - i]);
  }
  cout << memo2[1] << endl;
  for (int i = 1; i < n - 1; i++) {
    cout << max(memo1[i - 1], memo2[i + 1]) << endl;
  }
  cout << memo1[n - 2] << endl;
}
