#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << *max_element(a.begin() + 1, a.end()) << endl;
  for (int i = 1; i < n - 1; i++) {
    int ans = max(*max_element(a.begin(), a.begin() + i - 1),
                  *max_element(a.begin() + i + 1, a.end()));
    cout << ans << endl;
  }
  cout << *max_element(a.begin(), a.end() - 1) << endl;
  return 0;
}
