#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int oldm0 = 0, oldm1 = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      int max0 = *max_element(a.begin() + 1, a.end());
      cout << max0 << endl;
      oldm0 = a[0];
      oldm1 = max0;
      continue;
    }
    int m0 = oldm0 < a[i - 1] ? a[i - 1] : oldm0;
    int m1 = oldm1;
    if (oldm1 == a[i] && oldm1 != a[i + 1])
      m1 = *max_element(a.begin() + i + 1, a.end());
    cout << (m0 > m1 ? m0 : m1) << endl;
    oldm0 = m0;
    oldm1 = m1;
  }
  return 0;
}
