import numpy as np

N = int(input())
A_array = np.array([int(input()) for _ in range(N)])

print(A_array[1:].max())
for i in range(1, N-1):
    answer = max(A_array[:i].max(), A_array[i+1:].max())
    print(answer)
print(A_array[:N].max())