n=gets.to_i
a=[]
max=0
max_idx=0
n.times do|i|
	a[i]=gets.to_i
	if(a[i]>max)
		max=a[i]
		max_idx=i
	end
end
for i in 0..n-1
	if(i==max_idx)
		a.delete_at(max_idx)
		puts(a.max)
		i-=1
	else
		puts(max)
	end
end