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

maxa = max(A)

for i in range(N):
    if A[i] == maxa:
        if i == 0:
            print(max(A[1:]))
        elif i == N-1:
            print(max(A[:-1]))
        else:
            print(max(max(A[:i]), max(A[i+1:])))
    else:
        print(maxa)