N=int(input())
sequence=[]
for i in range(0,N):
    a=int(input())
    sequence.append(a)

A=max(sequence)
max_index_list=[]
while A in sequence:
    b=sequence.index(A)
    max_index_list.append(b)
    sequence[b]=0
print(sequence)
C=len(max_index_list)

Sequence=tuple(sequence)
for i in range(0,N):
    sequence2=list(Sequence)
    sequence2.pop(i)
    if i in max_index_list and C==1:
        print(max(sequence2))
    else:
        print(A)