
N = int(input())
A_lst = []
max_num = -1
max_index_lst = []
next_num = -1

for i in range(N):
    Ai = int(input())
    A_lst.append(Ai)
    if max_num == -1:
        max_num = Ai
        next_num = Ai
        max_index_lst.append(i)

    elif max_num <= Ai:
        if max_num == Ai:
            max_index_lst.append(i)
        else:
            max_index_lst = [i]
        next_num = max_num
        max_num = Ai

    
    elif next_num < Ai:
        next_num = Ai
print()
for i in range(N):
    if i in max_index_lst:
        if len(max_index_lst) == 1:
            print(next_num)
        else:
            print(max_num)
    else:
        print(max_num)