#include<stdio.h>

int main()
{
    long n, max1 = 0, max2 = 0, max1_index=-1, max2_index=-1, i, x;
    
    scanf("%ld", &n);
    for(i = 0; i<n; i++){
        scanf("%ld", &x);
        
        if(max1<=x){
            max2 = max1;
            max2_index = max1_index;
            
            max1 = x;
            max1_index = i;
        }
        else if (max2<=x){
            max2 = x;
            max2_index = i;
        }
        
    }
    
    for(i = 0; i<n; i++){
        if(i==max1_index) printf("%ld\n", max2);
        else printf("%ld\n", max1);
    }
    
    
    return 0;
}