import sys
from heapq import heappop,heappush,heapify

input=sys.stdin.readline

n=int(input())
a=[-int(input()) for _ in range(n)]

que=list(set(a))
heapify(que)


for i in range(n):
    v=heappop(que)
    if a[i]==v and que:
        v2=heappop(que)
        print(-v2)
        heappush(que,v2)
    else:
        print(-v)
    heappush(que,v)
