N=int(input())
A=[0 for i in range(N)]
for i in range(N):
  A[i]=int(input())
L=A.copy()
L.sort()
max1=L[N-1]
max2=L[N-2]
for i in range(N):
  if i == A.index(max1):
    print(max2)
  else:
    print(max1)