#include <bits/stdc++.h>
using namespace std;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
template <typename T>
void outputVec(const std::vector<T>& vec, const int precision = 0) {
  if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
  for (auto it = vec.begin(); it != vec.end() - 1; ++it) {
    std::cout << *it << " ";
  }
  std::cout << *(vec.end() - 1) << "\n";
}
template <typename T>
void outputVal(const T& res, const int precision = 0) {
  if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
  std::cout << res << "\n";
}
template <typename T>
T inputVal() {
  T a;
  std::cin >> a;
  return a;
}
template <typename T>
std::vector<T> inputVec(int N) {
  std::vector<T> vec(N);
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cin >> *it;
  }
  return vec;
}
template <typename T>
void inputVec(std::vector<T>& vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cin >> *it;
  }
}
template <class T>
inline bool chMin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chMax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void Main() {
  const int N = inputVal<int>();
  const vector<int> A = inputVec<int>(N);
  vector<int> lMax(N, 0);
  vector<int> rMax(N, 0);
  for (int i = 0; i < N; ++i) {
    lMax[i] = *max_element(A.begin(), A.begin() + i);
    rMax[i] = *max_element(A.begin() + i, A.end());
  }
  std::cout << rMax[1] << std::endl;
  for (int i = 1; i < N - 1; ++i) {
    cout << std::max(lMax[i - 1], rMax[i + 1]) << endl;
  }
  cout << lMax[N - 1] << endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  double tmp;
  cin >> tmp;
  return 0;
}
