n=int(raw_input())
m1,m2=0,0
i1=-1
for i in xrange(n):
    m=int(raw_input())
    if m>m1:
        m2,m1=m1,m
        i1=i
    elif m>m2:
        m2=m
for i in xrange(n):
    if i==i1:
        print m2
    else:
        print m1