n=int(input())
a=[]
m1=0
m2=0
for i in range(n):
    a.append(int(input()))
    if a>m1:
        m2=m1
        m1=a
        index=i
    elif m1==a:
        m2=a
    elif a>m2:
        m2=a
for i in range(n):
    if i==index:
        print(m2)
    else:
        print(m1)