#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 100000000;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t N;
  cin >> N;
  int64_t A[N + 1];
  for (int64_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t M = 0;
  for (int64_t i = 0; i < N; i++) {
    M = max(M, A[i]);
  }
  for (int64_t i = 0; i < N; i++) {
    if (A[i] != M) {
      cout << M << endl;
    } else {
      int64_t T = 0;
      for (int64_t j = 0; j < i; j++) {
        T = max(T, A[j]);
      }
      for (int64_t j = i + 1; j < N; j++) {
        T = max(T, A[j]);
      }
      cout << T << endl;
    }
  }
}
