def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	arr2 = arr.copy()
	arr2.sort()
	mx = arr2[-1]
	mx2 = arr2[-2]
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)

main()
