N=int(input())
A=[]
max1=0
ind1=0
max2=0
ind2=0
for i in range(N):
	A.append(int(input()))
	if max1 <= A[i]:	
		max2=max1
		ind2=ind1
		max1=A[i]
		ind1=i
for i in range(N):
	if max1 == A[i]:
		print(max2)
	else:
		print(max1)
	