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.pop(b)
C=len(max_index_list)

answer=[A]*N
if C!=N:
    for i in range (0,C):
        answer[max_index_list[i]]=max(sequence)
for i in range (0,N):
    print(answer[i])