N = int(input())
A = [int(input()) for i in range(N)]

A_length = len(A)
# print(A_length)

left = [A.pop(0)]
right = A

# print(left)
# print(right)

left_max = max(left)
right_max = max(right)
print(right_max)


for i in range(A_length-2):
    temp = right.pop(0)
    if temp == right_max:
        right_max = max(right)
    print(max(left_max, right_max))
    if temp > left_max:
        left_max = temp
    left.append(temp)

temp = right.pop(0)
if temp > left_max:
    lef_max = temp
left.append(temp)
print(left_max)
