#include <iostream>
using namespace std;

int main(void){
    int i, n;
    cin >> n ;
    int *a;
    a = new int[n];
    for(i=0; i<n; i++) cin >> a[i];
    
    int first;
    int f_max, s_max;
    first = 0;
    second = 0;
    f_max = 0;
    s_max = 0;
    for(i=0; i<n; i++){
        if(f_max<a[i]){
            s_max = f_max;
            first = i;
            f_max = a[i];
        }else if(s_max<a[i]){
            s_max = a[i];
        }
    }
    // output
    for(i=0; i<n; i++){
        if(i!=first){
            cout << f_max << endl;
        }else{
            cout << s_max << endl;
        }
    }
    
    
    return 0;
}
    