N = int(input())

A = []
max1 = 0
max2 = 0

for i in range(N):
  B = int(input())
  if B>max1:
    max1 = B
  else:
    if B>max2:
      max2 = B
      
  A.append(B) 

for i in range(N):
  if A[i] == max(A):
    print(max2)
  else:
    print(max1)
