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