n = int(input())

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

temp = sorted(arr)

max_element = temp[-1]

second_max = max_element

i = n - 2
while i >= 0 and second_max == max_element:
	second_max = temp[i]
	i -= 1

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