#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  assert(2 <= n && n <= 200000);
  vector<int> a_max(n, 0);
  int a_n = 0;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    assert(1 <= a && a <= 200000);
    for (int j = 0; j < i; j++) {
      if (a > a_max[j]) {
        if (0)
          cout << "a_max[" << j << "] = " << a_max[j] << " -> " << a << endl;
        a_max[j] = a;
      }
    }
    if (i < n - 1 && a_n < a) {
      a_n = a;
    }
  }
  a_max[n - 1] = a_n;
  for (int a : a_max) {
    cout << a << endl;
  }
  return 0;
}
