n=int(input())
a=[int(input()) for _ in range(n)]
ma=max(a)
b=a
for i in range(n):
  if b[i]==ma:
    b[i]=0
    p=i
    break
    
maa=max(b)
A=[]
for i in range(n):
  if i!=p:
    A.append(ma)
  else:
    A.append(maa)
    
print(A[i] for _ in range(n))
