#include<iostream>
using namespace std;

int main(){
	int max1=0,max2=0,tmp,n,s;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>tmp;
		if(tmp>max1){
			max2=max1;
			max1=tmp;
			s=i;
		}
		else if(max2<tmp)	max2=tmp;
	}
	for(int i=1;i<=n;++i){
		if(i==s)	cout<<max2<<endl;
		else		cout<<max1<<endl;
	}
} 