N = int(input())
maxA = 0
secondMaxA = 0
maxIndex = -1
for i in range(N):
  A = int(input())
  if A >= maxA:
    secondMaxA = maxA
    maxA = A
    maxIndex = 1
  elif A >= secondMaxA:
    secondMaxA = A

for i in range(N):
  if i == maxIndex:
    print(secondMaxA)
  else:
    print(maxA)