#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  int Max = *max_element(v.begin() + 1, v.end());
  cout << Max << "\n";
  for (int i = 1; i < n - 1; i++) {
    int max1 = *max_element(v.begin(), v.begin() + i - 1);
    int max2 = *max_element(v.begin() + i + 1, v.end());
    cout << max(max1, max2) << "\n";
  }
  Max = *max_element(v.begin(), v.end() - 1);
  cout << Max << "\n";
  return 0;
}
