a = input()
a = int(a)

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(input())
    suuretu_list.append(b)
    kari_list.append(b)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        e = max(kari_list)
        f = kari_list.index(e)
        kari_list.pop(f)
        g = max(kari_list)
        print(g)
        kari_list.append(g)