N =int(input())
nums = [int(input()) for i in range(N)]
A = set(nums)
m1 = sorted(A)[-1]
l = len(A)
if l == 1:
  print(m1)
else:
  for i in range(N):
    if nums[i] == m1:
      m2 = sorted(set(nums))[-2]
      print(m2)      
    else:
      print(m1)