#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N], B[N];
  int maxi, second;
  int index;
  maxi = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (maxi < A[i]) {
      maxi = A[i];
      index = i;
    }
  }
  memcpy(B, A, sizeof(A));
  sort(B, B + N);
  maxi, second = B[N - 1], B[N - 2];
  for (int i = 0; i < N; i++) {
    if (i != index) {
      cout << maxi << endl;
    } else {
      cout << second << endl;
    }
  }
}
