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

A_length = len(A)

a = [A.pop(0)]
print(max(A))

for i in range(A_length-2):
    temp = A.pop(i)
    print(max(max(a), max(A)))
    a.append(temp)

print(max(a))
