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