n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
aa = [0,0]
for i in range(n):
    if a[i] >= aa[-1]:
        aa[-1] = a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] = a[i]

if aa[-1] == aa[-2]:
    for i in range(n):
        print(aa[-1])
else:
    for i in range(n):
        if i == a.index(aa[-1]):
            print(aa[-2])
        else:
            print(aa[-1])