import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=[]
for _ in range(n):
    aa.append(int(input()))
a = aa[0]
b = max(aa[1:])
print(b)
for i in range(1,n):
    if a >= b:
        print(a)
        b = a
        a = aa[i]
    else:
        if aa[i] != b:
            print(b)
            a = aa[i]
        else:
            a = aa[i]
            b = max(aa[:i]+aa[i+1:])
            print(b)