#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, max, min;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  max = A[N - 1];
  for (int i = 0; i < N - 1; i++) {
    if (max == A[i + 1]) {
      min = A[i];
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (max != B[i]) {
      cout << max << endl;
    } else {
      cout << min << endl;
    }
  }
}
