a_max=0
a_max_next=0
A=[]
N=int(input())

for i in range(N):
    A.append(int(input()))
    if A[i]>a_max:
        a_max=A[i]
    elif A[i]>=a_max_next:
        a_max_next=A[i]

for i in range(N):
    if A[i]==a_max:
        print(a_max_next)
    else:
        print(a_max)