N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
A_i = [i for i in A if i != m]
if A_i == []:
    for i in range(N):
        print(A[i])
else:
    m_i = max(A_i)
    for i in range(N):
        if A[i] == m:
            print(m_i)
        else:
            print(m)
