#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
template <class T>
inline void chmax(T &a, const T &b) {
  if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
  if ((a) > (b)) (a) = (b);
}
template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
long long solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    cin >> a[i];
  }
  42;
  vector<long long> l(n);
  vector<long long> r(n);
  l[0] = a[0];
  r[n - 1] = a[n - 1];
  for (long long i = (long long)(1); i < (long long)(n); ++i) {
    l[i] = max(l[i - 1], a[i]);
  }
  for (long long i = (long long)((n - 1) - 1); i >= (long long)(0); --i) {
    r[i] = max(r[i + 1], a[i]);
  }
  42;
  42;
  cout << r[1] << endl;
  for (long long i = (long long)(1); i < (long long)(n - 1); ++i) {
    cout << max(l[i - 1], r[i + 1]) << endl;
  }
  cout << l[n - 1] << endl;
  return 0;
}
signed main() {
  solve();
  return 0;
}
