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

FIRST = max(A)
A_ = [a for a in A if a != FIRST]
if A_:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)
else:
    for i in range(N):
        print(FIRST)