#include <bits/stdc++.h>
template <typename T>
void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
int main() {
  int N, a;
  std::vector<int> A;
  std::vector<int> A_tmp;
  int tmp;
  int tmp_A_max = 0, A_max;
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> a;
    A.push_back(a);
  }
  for (int j = 0; j < N; ++j) {
    tmp = A[j];
    A.erase(A.begin());
    A_max = *std::max_element(A.begin(), A.end());
    if (!A_tmp.empty())
      tmp_A_max = *std::max_element(A_tmp.begin(), A_tmp.end());
    if (A_max > tmp_A_max) {
      std::cout << A_max << '\n';
    } else {
      std::cout << tmp_A_max << '\n';
    }
    A_tmp.push_back(tmp);
  }
}
