def resolve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxA = max(A)
    countMax = A.count(maxA)
    if countMax > 1:
        [print(maxA) for _ in range(N)]
    else:
        next = -1
        maxIdx = A.index(maxA)
        if maxIdx == 0:
            next = max(A[1:])
        elif maxIdx == N - 1:
            next = max(A[:N - 1])
        else:
            next = max(max(A[0:maxIdx], A[maxIdx + 1:N]))
        for i in range(N):
            if not i == maxIdx:
                print(maxA)
            else:
                print(next)


resolve()
