N = int(input())
A = []
my_max = 0
for _ in range(N):
    a = int(input())
    A.append(a)
    my_max = max(my_max, a)

max_count = A.count(a)

if max_count > 1:
    [print(my_max) for _ in range(N)]
else:
    my_next_max = max([a for a in A if a != my_max])
    [print(my_max) if a != my_max else print(my_next_max) for a in A]