
N = int(input())

A = []

maxi = 0
sec = 0

for i in range(N):

    a = int(input())
    A.append(a)


    if A[maxi] <= a:
        sec = maxi
        maxi = i
        #print (maxi ,sec , i ,a)

    elif A[sec] <= a:

        sec = i

for i in range(N):

    if i == maxi:
        print (A[sec])

    else:
        print (A[maxi])
