#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int maxf = -1;
  auto maxb = max_element(a.begin() + 1, a.end());
  int ret;
  cout << *maxb << endl;
  for (int i = 1; i < n; i++) {
    maxf = max(maxf, a[i - 1]);
    if (maxb <= a.begin() + i + 1) {
      maxb = max_element(a.begin() + i + 1, a.end());
    }
    if (i == n - 1) {
      ret = maxf;
    } else {
      ret = max(maxf, *maxb);
    }
    cout << ret << endl;
  }
  return 0;
}
