n = int(input())
a = []
for _ in range(n):
	a.append(int(input()))
max1 = max(a)
max2 = -1
for c in a:
	if(c==max1):
		continue
	max2 = max(max2,c)

if(max2==-1):
	max2 = max1

for i in a:
	if(i==max1):
		print(max2)
	else:
		print(max1)
