N = int(input())
A = [int(input()) for i in range(N)]

ma = max(A)
B = sorted(A)

if B[0] == ma :
    ma2 = ma
else :
    for i in range(N-1,-1,-1) :
        if B[i] != ma :
            ma2 = B[i]
            break



for a in A :
    if a == ma :
        print(ma2)
    else :
        print(ma)
        
