#include <bits/stdc++.h>
using namespace std;
long long N, A[200001], B[200001];
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  for (long long i = 0; i < N - 1; i++) {
    if (A[i] < A[i + 1]) {
      long long T = A[i];
      A[i] = A[i + 1];
      A[i + 1] = T;
    }
  }
  for (long long i = 0; i < N; i++) {
    if (B[i] == A[0]) {
      cout << A[1] << endl;
    } else {
      cout << A[0] << endl;
    }
  }
  return 0;
}
