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

pre_max = 0
af_max = max(A[1:])
print(af_max)
for ii in range(1, N - 1):
    af_max = max(A[ii + 1:])
    pre_max = max(A[ii - 1], pre_max)
    print(max(pre_max, af_max))

print (max(pre_max, A[N - 2]))
