# Setup
import sys
sys.setrecursionlimit(4100000)
n = int(input())
a = [int(input()) for i in range(n)]
heap = []
for i in range(n):
    heapq.heappush(heap,-a[i])
for i in range(n):
    temp = heapq.heappop(heap)
    if -a[i] == temp:
        temp2 = heapq.heappop(heap)
        print(-temp2)
        heapq.heappush(heap,temp)
        heapq.heappush(heap,temp2)
    else:
        print(-temp)
        heapq.heappush(heap,temp)