#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  int left[N];
  int right[N];
  int max_e = std::numeric_limits<int>::min();
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    max_e = std::max(A[i], max_e);
    left[i] = max_e;
  }
  if (N == 1) {
    cout << A[0] << "\n";
    return 0;
  }
  max_e = std::numeric_limits<int>::min();
  for (int i = N - 1; i >= 0; i--) {
    max_e = std::max(A[i], max_e);
    right[i] = max_e;
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      cout << A[i + 1] << "\n";
    } else if (i == N - 1) {
      cout << A[i - 1] << "\n";
    } else {
      cout << std::max(left[i - 1], right[i + 1]) << "\n";
    }
  }
  return 0;
}
