def large(arr,n):
	first = second = -1
	for i in range(n):
		if arr[i]>first:
			second = first
			first = arr[i]
		elif arr[i]>second and arr[i]!=first:
			second = arr[i]
	if(second == -1):
		return first,first
	else:
		return second, first


n = int(input())
arr = []
brr = []
for _ in range(n):
	t = int(input())
	arr.append(t)
	# brr.append(t)
m2,m = large(arr,n)
for i in arr:
	if(i!=m):
		print(m)
	else:
		print(m2)

