#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
ll b[220000];
ll m1[220000], m2[220000];
int main() {
  ll n;
  cin >> n;
  for (ll i = ll(0); i < ll(n); i++) cin >> b[i];
  m1[0] = 0;
  m2[n + 1] = 0;
  m1[1] = b[0];
  m2[n] = b[n - 1];
  for (ll i = ll(1); i < ll(n); i++) m1[i + 1] = max(m1[i], b[i]);
  for (ll i = ll(n - 2); i >= ll(0); i--) m2[i + 1] = max(m2[i], b[i - 1]);
  for (ll i = ll(2); i < ll(n + 1); i++)
    cout << max(m1[i - 1], m2[i + 1]) << endl;
}
