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