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
while (1):
    if sort_A[k] != sort_A[k+1]:
        A_second = sort_A[k+1]
        break
    k += 1
for i in range(N):
    if A_list[i] == sort_A[0]:
        print(A_second)
    else:
        print(sort_A[0])