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