#include<bits/stdc++.h>
#define M 200005
using namespace std;
int n,A[M],la[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	la[n]=A[n];
	for(int i=n-1;i>=1;i--)la[i]=max(la[i+1],A[i]);
	int mx=0;
	for(int i=1;i<=n;i++){
		printf("%d\n",max(la[i+1],mx));	
		mx=max(mx,A[i]);
	}
	return 0;
}