# input
N = int(input())
A = []

#list
for i in range(N):
    n = int(input())
    A.append(n)

#max
print(sorted(A[1:])[-1])

if N>2:
    for i in range(1, N-1):
        A_=sorted(A[:i])
        A__=sorted(A[i+1:])
        print(max(A_[-1], A__[-1]))

print(sorted(A[:-1])[-1])