n=int(input())
l =[]
for i in range(n):
        a = int(input())
        l.append(a)
        b = max(l)
for i in range(n):
        if l[i] == b:
                del l[i]
                print(max(l))
                l.insert(i,b)

        else:
                print(b)
