n = int(input())
temp = []
for i in range(n):
	temp.append(int(input()))

sort = temp[:]

sort.sort()

maximum = sort[-1]

print(maximum)

for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])

