import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0

#print(g)
while i!=n:

    a=s[0]
    del s[0]
    if maxx==a and g<2:
        print(max(s))
    else:
        print(maxx)


    s.append(a)
    i+=1