def main():
    N=int(input())
    A=[0 for i in range(0,N)]
    for i in range(0,N):
        A[i]=int(input())
    L=[0 for i in range(0,N)]
    R=[0 for i in range(0,N)]
    L[0]=A[0]
    R[0]=A[N-1]
    for i in range(0,N-1):
        L[i+1]=max(A[i+1],L[i])
        R[i+1]=max(A[N-i-2],R[i])
    for i in range(0,N):
        if i==0:
            print(R[N-2])
        elif i==N-1:
            print(L[N-2])
        else:
            print(max(L[i-1],R[i-1]))

if __name__ == '__main__':
    main()