#include <bits/stdc++.h>
using namespace std;
int arr[200003] = {};
int mx[200003] = {};
int mx_rev[200003] = {};
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  mx[0] = arr[0];
  for (int i = 1; i <= n; i++) {
    mx[i] = max(mx[i - 1], arr[i]);
  }
  mx_rev[n - 1] = arr[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    mx_rev[i] = max(mx_rev[i + 1], arr[i]);
  }
  cout << mx_rev[1] << endl;
  for (int i = 1; i < n - 1; i++) {
    cout << max(mx[i - 1], mx_rev[i + 1]) << endl;
  }
  cout << mx[n - 1] << endl;
  return 0;
}
