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

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

b.sort()
m = 0
l = n+1

for i in range(n):
    m = 0
    l = n+1
    while a[i] != b[(m+l)//2]:
        if a[i] < b[(m+l)//2]:
            l //= 2
        else:
            m = i
    tmp = b[(m+l)//2]
    b[(m+l)//2] = 0
    print(max(b))
    b[(m+l)//2] = tmp