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