N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
sort_A = sorted(A_list, reverse = True)
k = 0
for i in range(1, len(sort_A)):
    if sort_A[i] != sort_A[i-1]:
        A_second = sort_A[i]
        break
    if i == len(sort_A)-1:
        A_second = sort_A[0]
for i in range(N):
    if A_list[i] == sort_A[0]:
        print(A_second)
    else:
        print(sort_A[0])