#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
bool debug = false;
int f(int a, int b) {
  if (a < b)
    return b;
  else
    return a;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (max < a[i]) {
      b[i] = a[i];
      max = a[i];
    } else {
      b[i] = max;
    }
    if (max < a[n - 1 - i]) {
      max = a[n - 1 - i];
    }
    c[n - 1 - i] = max;
  }
  cout << c[1] << endl;
  for (int i = 1; i < n - 1; i++) {
    cout << f(b[i - 1], c[i + 1]) << endl;
  }
  cout << b[n - 2] << endl;
  return 0;
}
