n = int(input())

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

max_element = max(arr)
second_max = -1

for i in arr:
	if i > second_max and i != max_element:
		second_max = i

for i in arr:
	if i != max_element:
		print(max_element)
	else:
		print(second_max)