#include<iostream>
#include<algorithm>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
    int n; cin >> n;
    int max_number = 0, second_max_number = 0;
    int index;

    REP(i, n){
        int x; cin >> x;
        if(max_number <= x){
            index = i;
            second_max_number = max_number;
            max_number = x;
        }else second_max_number = max(second_max_number, x);
    }

    REP(i, n){
        if(index != i) cout << max_number << '\n';
        else cout << second_max_number << '\n';
    }
