n = int(input())

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

m = max(A)

print(max(A[1:]))

for i in range(1, n-1):
    if A[i] < m:
        print(m)
    else:
        print(max(max(A[:i]), max(A[i+1:])))

print(max(A[:n-1]))