#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long A[N];
  long long n1;
  long long n2;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0) {
      n1 = A[i];
      n2 = 0;
    };
    if (n1 >= A[i] && A[i] > n2) n2 = A[i];
    if (A[i] > n1) n1 = A[i];
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == n1)
      cout << n2 << endl;
    else
      cout << n1 << endl;
  }
}
