#include<bits/stdc++.h>
using namespace std;
int n,fm,fm1,sm,sm1,a[200100];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>sm){
			if(a[i]>fm) fm=a[i],fm1=i;
			else sm=a[i],sm1=i;
		}
	}
	for(int i=1;i<=n;i++){
		if(fm1==i) printf("%d\n",sm);
		else printf("%d\n",fm);
	}
}