n = int(input())
a_lst = []
for i in range(n):
    a = int(input())
    a_lst.append(a)

max_a = max(a_lst)
max_a_id_lst = [i for i, elem in enumerate(a_lst) if elem == max_a]

for i in range(n):
    if i in max_a_id_lst:
        if len(max_a_id_lst) == 1:
            a_lst.remove(max_a)
            print(max(a_lst))
        else:
            print(max_a)
    else:
        print(max_a)