N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
    
    
    
import copy
U=copy.deepcopy(A)
del U[U.index(max(U))]
X=max(U)
Q=max(A)
for i in range(N):
    if i==A.index(Q):
        print(X)
    else:
        print(Q)