#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  int val = A[0];
  int max_val = *std::max_element(A.cbegin() + 1, A.cend());
  std::cout << max_val << std::endl;
  for (int i = 1; i < N; ++i) {
    if (max_val != A[i]) {
      max_val = std::max(max_val, val);
    } else {
      const auto it = A.cbegin() + i;
      max_val = std::max(*std::max_element(A.cbegin(), it),
                         *std::max_element(it + 1, A.cend()));
    }
    std::cout << max_val << std::endl;
    val = A[i];
  }
}
