N = int(input())
A = []
for i in range(N):
  a = int(input())
  A.append(a)
  
A2 = sorted(A)
mx1 = A2[-1]
mx2 = A2[-2]

for i in range(N):
  if i == A.index(mx1):
    print(mx2)
  else:
    print(mx1)
