N = int(input())
list_A = []

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)

for i in range(N):
    if list_A[i] == A:
        list_A[i] = 0
        print(max(list_A))
        list_A[i] = A
    else:
        print(A)