N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
for n in range(N):
    if A[n] < m:
        print(m)
        continue
    elif n == 0:
        print(max(A[n + 1:]))
    elif n == N - 1:
        print(max(A[:n]))
    else:
        print(max(max(A[:n]), max(A[n + 1:])))