#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[1000000];
  int l[1000000];
  int r[1000000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  l[0] = a[0];
  for (int i = 1; i <= n - 2; i++) {
    l[i] = max(l[i - 1], a[i]);
  }
  r[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 1; i--) {
    r[i] = max(l[i + 1], a[i]);
  }
  cout << r[1] << "\n";
  for (int i = 1; i < n - 1; i++) cout << max(l[i - 1], r[i + 1]) << "\n";
  cout << l[n - 2] << "\n";
}
