n = int(input())
arr = []
brr = []
for _ in range(n):
	t = input()
	arr.append(t)
	brr.append(t)
m = max(arr)
brr.sort()
m2 = m
for i in range(n-1,-1,-1):
	if(brr[i]!=m):
		m2 = brr[i]
		break
for i in arr:
	if(i!=m):
		print(m)
	else:
		print(m2)

