n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = [l for l in A if l != maxa]

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)