from collections import defaultdict from heapq import heappush, heappop n = int(input()) A = list(map(int, input().split())) counter = defaultdict(int) for i in range(n): counter[A[i]] += 1 ANS = [-1 for _ in range(n)] H = [] for i in range(n): a = A[i] if len(H) == 0: ANS[i] = a else: max_ = -H[0] if max_ > a: ANS[i] = max_ else: ANS[i] = a counter[a] -= 1 if counter[a] > 0: heappush(H, -a) elif counter[a] == 0 and len(H) > 0: if a == -H[0]: heappop(H) while H: max_ = -H[0] if counter[max_] == 0: heappop(H) continue break print(*ANS)