N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
a = max(A)
B = sorted(set(A))
if(len(B) > 1) :
	b = B[-2]
else :
	b = B[0]
for i in range(N) :
	if(A[i] == a) :
		print(b)
	else :
		print(a)