#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  int tmp = 0;
  int idx = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (tmp <= A[i]) tmp = A[i];
    idx = i;
  }
  sort(A, A + N, greater<int>());
  for (int i = 0; i < N; i++) {
    if (i == idx)
      cout << A[1] << endl;
    else
      cout << A[0] << endl;
  }
}
