def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	mx = -10000
	mx2 = -11111
	for i in range(len(arr)):
		if arr[i]>mx:
			mx = arr[i]
		if arr[i]>mx2 and arr[i]<mx:
			mx2 = arr[i]
	if mx2==-11111:
		mx2 = mx
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)


main()
