#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9;
const long long mod = 2019;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int x1 = a[2];
  for (int i = 2; i < N - 1; i++) {
    x1 = max(x1, a[i + 1]);
  }
  int ans;
  cout << max(a[1], x1) << endl;
  int x2 = a[0];
  for (int i = 1; i < N; i++) {
    if (x2 < a[i - 1]) {
      x2 = a[i - 1];
    }
    if (a[i] == x1) {
      x1 = a[i + 1];
      for (int k = i + 1; k < N - 1; k++) {
        x1 = max(a[k], x1);
      }
    }
    cout << max(x2, x1) << endl;
  }
  return 0;
}
