n = int(input())
a = [0]*(n)
num = 0
max = 0
smax = 0
for i in range(n):
    a[i] = int(input())
for i in range(n):
    if a[i] > max:
        max = a[i]
        num = i
for j in range(n):
    if j != i:
        if a[j] > smax:
            smax = a[j]
for j in range(n):
    if j == i:
        max = smax
    print(max)