# input
n = int(input())
A = [int(input()) for _ in range(n)]
B = sorted(A, reverse = True)

# maxの値と場所, maxを除いた場合のnext_maxを求めておく

# max
if B[0] == B[1] : 
    for i in range(len(A)) : 
        print(B[0])

else : 
    for i in range(len(A)) :
        if i == A.index(B[0]) : 
            print(B[1])
        else : 
            print(B[0])