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

if (N<=2):
    print(A[0])
    print(A[1])
else:
    M1=[0]
    M2=[max(A[1:N-1])]
    for i in range(1,N-1):
        M1.append(max(A[0:i]))
        M2.append(max(A[i+1:N]))
    M1.append(max(A[0:N-1]))
    M2.append(0)
    for i in range(N):
        print(max(M1[i], M2[i]))
