n = int(input())

a = []
max_a = 0
next_a = 0
count_max_a = 0
for _ in range(n):
    v = int(input())
    a.append(v)
    if (max_a < v):
        max_a = v
        count_max_a = 1
        if next_a == 0:
            next_a = v
    elif (max_a == v):
        count_max_a += 1
    elif (next_a < v):
        next_a = v

for v in a:
    if v != max_a:
        print(max_a)
    elif v == max_a:
        if count_max_a == 1:
            print(next_a)
        else:
            print(max_a)
