N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
i=l.index(max(l))
if i==0:
  l1=l[1:]
  print(max(l1))
  for a in range(N-1):
    print(max(l))
elif i==N:
  l1=l[:N]
  for a in range(N-1):
    print(max(l))
  print(max(l1))
else:
  l1=l[:i]+l[i+1:]
  for a in range(i):
    print(max(l))
  print(max(l1))
  for a in range(N-i-1):
    print(max(l))