N = int(input())
A_list = []
A_count_list = []
for i in range(N):
    A = int(input())
    A_count_list.append(A)
    for j in range(len(A_list)):
        if A_list[j] < A:
            A_list.insert(j, A)
            A = 0
    if A != 0:
        A_list.append(A)
max_index = A_count_list.index(max(A_count_list))
for i in range(N):
    if i == max_index:
        print(A_list[1])
    else:
        print(A_list[0])