#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> ma1(N), ma2(N);
  for (int i = 0; i < N; i++) chmax(ma1[i], A[i]);
  for (int i = N - 1; i >= 0; i--) chmax(ma2[i], A[i]);
  for (int i = 0; i < N; i++) {
    if (i == 0)
      cout << ma2[i + 1] << endl;
    else if (i == N - 1)
      cout << ma1[i - 1] << endl;
    else
      cout << max(ma1[i - 1], ma2[i + 1]) << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
