n=int(input())

a=[]
sub=[]
first=-1

for i in range(n):
    inp = int(input())
    a.append(inp)
    if inp >= first:
        first = inp

b=sorted(list(set(a)))

if len(b)==1:
    second=first
else:
    second=b[-2]

for aa in a:
    if aa == first:
        print(second)
    else:
        print(first)