#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, s;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> s;
    a.emplace_back(s);
  }
  int ma;
  int ma1, ma2;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      cout << *max_element(a.begin() + 1, a.end()) << endl;
    } else if (i == n - 1) {
      cout << *max_element(a.begin(), a.end() - 1) << endl;
    } else {
      ma1 = *max_element(a.begin(), a.begin() + i - 1);
      ma2 = *max_element(a.begin() + i + 1, a.end());
      if (ma1 > ma2) {
        cout << ma1 << endl;
      } else {
        cout << ma2 << endl;
      }
    }
  }
  return 0;
}
