#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define f first
#define s second
int a[200000]={0};
int main(){
int n,i,j;
pair<int,int> mx,sb;
mx.f=0;
sb.f=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(mx.f<=a[i]){
sb.f=mx.f;
sb.s=mx.s;
mx.f=a[i].f;
mx.s=i;
}
else if(sb.f<a[i]){
sb.f=a[i];
sb.s=i;
}
}
for(i=0;i<n;i++){
if(i!=mx.s)
printf("%d\n",mx.f);
else
printf("%d\n",sb.f);
}
return 0;
}
