import sys
n=input()
ls=[]
for _ in xrange(n):
    ls.append(input())
m1= max(ls)
i=ls.index(m1)
del ls[ls.index(m1)]
m2= max(ls)
ls.insert(i,m1)
for i in xrange(n):
    if ls[i]==m1:
        print m2
    else:
        print m1