#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int max = *max_element(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (A[i] == max) A[i] = 0;
  }
  int max1 = *max_element(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (A[i] != max) cout << max << endl;
    if (A[i] == max) {
      cout << max1 << endl;
    }
  }
}
