N = int(input())
A_list = [int(input()) for x in range(N)]

sorted_list = sorted(A_list, reverse = True)
max_1st = sorted_list[0]
for num in sorted_list:
    max_2nd = num
    if max_1st != max_2nd:
        break

for num in A_list:
    if num != max_1st:
        print(max_1st)
    else:
        print(max_2nd)