N = int(input())
A = [int(input()) for i in range(N)]
tmp = 0
for i in range(N):
    if A[i] > A[tmp]:
        tmp = i
B = sorted(A)
answer = [A[tmp]]*N
A[tmp] = B[0]
C = sorted(A)
answer[tmp] = A[-1]

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