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

ans[0] = max(A[1:])
ans[N-1] = max(A[:-1])

for i in range(1, N-1):
    ans[i] = max(max(A[:i]), max(A[i+1:]))

print(*ans, sep="\n")