n = int(input())
a = []

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

ma = max(a)
max_i = a.index(ma)
b = []

for j in range(n):
    if j != max_i:
        b.append(a[i])

mb = max(b)

for i in range(n):
    if i != max_i:
        print(ma)
    else:
        print(mb)
