import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A = heapq.heappop(A_heap)
        pop_A_list.append(pop_A)

    print(-(pop_A))
    for i in pop_A_list:
        heapq.heappush(A_heap, i)