
N = int(input())
if 2 <= N <= 200000:
    Input = [input() for i in range(N)]

result = []
n = N
s = 1
m = 2


for i in range(N):

    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        if 1<= Input[m] <= 200000 :
            result.append(Input[m])
            m  += 1
            s  += 1
    else:
        if 1<= Input[s] <= 200000 :
            result.append(Input[s])
            m  += 1
            s  += 1


for i in  range(len(result)):
    print(result[i])
