#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int A[N];
    int first = 0;
    int second = 0;
    for(int i = 0;i < N;i++){
        cin >> a[i];
        if(a[i] > first){
            first = a[i];
        }else if(a[i > second){
            second = a[i]
        }
    }
    
    for(int i = 0;i < N;i++){
        if(a[i] == first){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }
    
}
