import numpy as np

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

num_max = max(nums)

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

