N = int(input())
A = [int(input()) for _ in range(N)]
AMax = max(A)
x = A.index(AMax)
Aelse = A[:x]+A[x+1:]
AelseMax = max(Aelse)
if AMax == AelseMax:
    for i in range(N):
        print(AMax)
else:
    for i in range(N):
        if x == i:
            print(AMax)
        else:
            print(AelseMax)