#include <bits/stdc++.h>
using namespace std;
const int maxN = 200000;
int main() {
  long long N;
  long long A[maxN];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long B = *max_element(A, A + N);
  for (int i = 0; i < N; i++) {
    if (A[i] != B) {
      cout << B << endl;
    } else {
      A[i] = 0;
      cout << *max_element(A, A + N) << endl;
    }
  }
}
