# n = 3
n = int(input())

lg = 0

arr = [0]*n

for i in range(n):
	arr[i] = int(input())
	if i==0:
		lg = i 
	elif i==1:
		if arr[lg] > arr[i]:
			slg = lg
			lg = i 
		else:
			slg = i			
	elif arr[i] >= arr[lg]:
		slg = lg
		lg = i
	elif arr[i] >= arr[slg]:
		slg = i 


for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])