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

if n > 1:
	print(max(temp[1:n]))

	for i in range(1,n-1):
		print(max(max(temp[0:i]), max(temp[i+1:n])))

	print(max(temp[0:n-1]))

else:
	print(temp[0])