import numpy as np

n =	int(input())
nums = [int(input()) for i in range(n)]

num_max = np.max(nums)
next_max = sorted(nums)[-2]


for idx, el in enumerate(nums):
	del nums[idx]
	if num_max == el:
		print(next_max)		
	else:
		print(num_max)
	nums.insert(idx, el)

