Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that:

  for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. 

The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set.

If such array doesn't exist, determine this.


-----Input-----

The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$.

The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. 


-----Output-----

If there's no such array, print a single line containing $-1$.

Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$)

If there are multiple answers, print any.


-----Examples-----
Input
3
1 2 3

Output
0 1 2 
Input
4
0 0 0 2

Output
1 3 4 0 
Input
3
1 1 3

Output
0 2 1 


-----Note-----

In the second test case, other answers like $[1,1,1,0]$, for example, are valid.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Complete search

Constructive algorithms


Solutions:
n = int(input())
l = list(map(int, input().split()))
ans = []
d = [False] * 202000
for i in l:
	d[i] = True
for i in range(202000):
	if not d[i]:
		ans.append(i)
lp = 1
print(ans[0], end=' ')
for i in range(1, n):
	if l[i] != l[i - 1]:
		print(l[i - 1], end=' ')
	else:
		print(ans[lp], end=' ')
		lp += 1
print()


n = int(input())
a = list(map(int, input().split()))
l = [0] * (n + 1)
flag = 0
b = []
c = []
import heapq
for i in range(n):
	if a[i] > i + 1:
		flag = 1
		break
	l[a[i]] += 1
for i in range(n + 1):
	if l[i] == 0:
		c.append(i)
heapq.heapify(c)
if flag == 1:
	print(-1)
else:
	for i in range(n):
		j = heapq.heappop(c)
		b.append(j)
		l[j] -= 1
		l[a[i]] -= 1
		if l[a[i]] == 0:
			heapq.heappush(c, a[i])
	print(' '.join(map(str, b)))


def get_not_elements(a: list):
	elements = set(a)
	max_element = a[-1] + 2
	not_elements = []
	for i in range(0, max_element):
		if not i in elements:
			not_elements.append(i)
	not_elements.reverse()
	return not_elements

def is_valid(a: list):
	for i in range(len(a)):
		if a[i] - 1 > i:
			return False
	return True

def generate_array(a: list):
	stack_ = get_not_elements(a)
	b = [-1 for i in range(len(a))]
	val = a[0]
	for i in range(1, len(a)):
		if a[i] != val:
			b[i] = val
			val = a[i]
	if len(stack_) > 0:
		val = stack_.pop()
	else:
		val = a[0]
	for i in range(len(a)):
		if b[i] == -1:
			b[i] = val
			if len(stack_) > 0:
				val = stack_.pop()
	return b
size = int(input())
array = [int(i) for i in input().split()]
if not is_valid(array):
	print(-1)
else:
	b = generate_array(array)
	b = ' '.join([str(i) for i in b])
	print(b)


n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a)
if a1 != a:
	print(-1)
else:
	m = max(a) - 1
	mm = m + 10
	ans = [-1] * n
	has = [0] * (n + 10)
	for i in range(n - 1, -1, -1):
		has[a[i]] = 1
		if a[i] > i + 1:
			print(-1)
			exit()
		elif i > 0:
			if a[i - 1] != a[i]:
				ans[i] = a[i - 1]
	c = 0
	for i in range(n):
		if ans[i] != -1:
			continue
		while has[c]:
			c += 1
		ans[i] = c
		has[c] = 1
	print(*ans)


a = int(input())
z = list(map(int, input().split()))
ans = [-1 for i in range(len(z))]
from collections import *
al = defaultdict(int)
for i in range(1, len(z)):
	if z[i] != z[i - 1]:
		ans[i] = z[i - 1]
for i in range(len(z)):
	al[z[i]] = 1
temp = []
for i in range(len(z) + 1):
	if al[i] == 0:
		temp.append(i)
c1 = 0
for i in range(len(ans)):
	if ans[i] == -1:
		ans[i] = temp[c1]
		c1 += 1
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l1 = [0] * 1000004
lf = [-1] * 1000004
for i in range(1, n):
	l1[l[i]] = 1
	if l[i] != l[i - 1]:
		lf[i] = l[i - 1]
l1[l[0]] = 1
m = 0
for i in range(n):
	if lf[i] == -1:
		while l1[m] == 1:
			m += 1
		lf[i] = m
		l1[m] = 1
for i in range(n):
	print(lf[i], end=' ')
print()


from queue import Queue

def main():
	test = 1
	for _ in range(test):
		n = int(input())
		ara = [int(num) for num in input().split()]
		mark = [True for _ in range(n + 1)]
		for num in ara:
			mark[num] = False
		take_from = Queue()
		for index in range(n + 1):
			if mark[index]:
				take_from.put(index)
		ans = []
		ans.append(take_from.get())
		for index in range(1, n):
			if ara[index] != ara[index - 1]:
				ans.append(ara[index - 1])
			elif not take_from.empty():
				ans.append(take_from.get())
			else:
				ans.append(n + 1)
		ans = ' '.join(map(str, ans))
		print(ans)
main()


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 998244353

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq

def solution(a, n):
	last = 0
	missing = []
	for x in a:
		if x != last:
			missing.extend(range(last + 1, x))
			last = x
	missing = [max(a) + 1] + missing[::-1]
	a = [0] + a
	sol = []
	for i in range(1, n + 1):
		if a[i] == a[i - 1]:
			if len(missing) > 1:
				sol.append(missing.pop())
			else:
				sol.append(missing[0])
		else:
			sol.append(a[i - 1])
	return ' '.join(map(str, sol))

def main():
	T = 1
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

def main():
	n = itg()
	arr = tuple(mpint())
	have_ans = all([arr[i] <= arr[i + 1] and arr[i] <= i + 1 for i in range(n - 1)])
	if not have_ans:
		return [-1]
	aa = set(arr)
	bb = sorted(set(range(n + 7)) - aa, reverse=True)
	aa = sorted(aa, reverse=True)
	ans = [bb.pop()]
	for i in range(1, n):
		if arr[i - 1] != arr[i]:
			ans.append(aa.pop())
		else:
			ans.append(bb.pop())
	return ans
print(*main())


n = int(input())
l = set()
a = list(map(int, input().split()))
l = set(a)
ans = 0
ans_t = []
v = []
for _ in range(n):
	if not _:
		while ans in l:
			ans = ans + 1
		ans_t.append(ans)
		ans = ans + 1
	elif a[_] != a[_ - 1]:
		ans_t.append(a[_ - 1])
	else:
		while ans in l:
			ans = ans + 1
		ans_t.append(ans)
		ans = ans + 1
print(*ans_t, sep=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = [-1] * n
set_a = set(a)
for i in range(n - 1, 0, -1):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
c = 0
for i in range(n):
	if b[i] == -1:
		while c in set_a:
			c += 1
		b[i] = c
		c += 1
if max(a) - max(b) > 1:
	print(-1)
else:
	print(*b)


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))

def fill_with(x):
	if x not in s:
		return True
	return False
n = iinput()
a = linput()
s = set(a)
b = [0] * n
x = 0
while not fill_with(x):
	x += 1
b[0] = x
x += 1
for i in range(1, n):
	if a[i] > a[i - 1]:
		b[i] = a[i - 1]
	else:
		while not fill_with(x):
			x += 1
		b[i] = x
		x += 1
print(*b)


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().strip().split()))
c = set(a)
d = []
for i in range(n + 1):
	if i not in c:
		d.append(i)
b = []
j = 0
for i in range(n):
	if i != 0:
		if a[i - 1] < a[i]:
			b.append(a[i - 1])
		else:
			b.append(d[j])
			j = j + 1
	else:
		b.append(d[j])
		j = j + 1
print(*b)


def answer(n, A):
	q = [0] * (n + 2)
	for i in A:
		q[i] = 1
	l = [i for i in range(n + 2) if q[i] == 0]
	b = []
	for i in range(n - 1):
		if A[i] != A[i + 1]:
			b.append(l[0])
			l[0] = A[i]
		else:
			b.append(l[0])
			del l[0]
	b.append(l.pop(0))
	return b
n = int(input())
A = list(map(int, input().split()))
print(*answer(n, A))


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	reserve = set()
	if lst[0] > 1:
		print(-1)
		return
	for i in range(0, n):
		if lst[i] > i + 1:
			print(-1)
			return
		reserve.add(lst[i])
	can_use = []
	cur = lst[0]
	for i in range(0, n + 1):
		if not i in reserve:
			can_use.append(i)
	can_use.reverse()
	used = []
	for i in range(0, n):
		if lst[i] == cur:
			if len(can_use) == 0:
				print(-1)
				return
			used.append(can_use.pop())
		else:
			if len(can_use) != 0 and can_use[-1] < cur:
				print(-1)
				return
			used.append(cur)
			cur = lst[i]
	line = ''
	for i in used:
		line += str(i) + ' '
	print(line)
t = 1
for i in range(t):
	main()


from heapq import heappush, heappop
n = int(input())
ar = list(map(int, input().split()))
valid = True
s = []
for i in range(n):
	if ar[i] > i + 1:
		valid = False
		break
	elif i > 0:
		for j in range(ar[i - 1] + 1, ar[i]):
			heappush(s, j)
	elif ar[0] == 1:
		heappush(s, 0)
if not valid:
	print(-1)
else:
	maxi = ar[-1] + 1
	s_len = len(s)
	for i in range(s_len, n):
		heappush(s, maxi)
		maxi += 1
	ans = []
	for i in range(n):
		k = heappop(s)
		ans.append(k)
		if i + 1 < n and ar[i] != ar[i + 1]:
			heappush(s, ar[i])
	print(*ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
n = II()
a = LI()
(b, s) = ([-1] * n, set([a[-1]]))
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		s.add(b[i])
v = 0
for i in range(n):
	while v in s:
		v += 1
	if b[i] == -1:
		b[i] = v
		s.add(v)
print(*b)


def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = [-1] * n
	N = 10 ** 6
	now = N
	TB = [True] * N
	if A[0] > 0:
		B[0] = 0
		TB[0] = False
	for i in range(1, n):
		a = A[i]
		ab = A[i - 1]
		if ab < a:
			if TB[ab]:
				B[i] = ab
				TB[ab] = False
	TB[A[-1]] = False
	indexb = 0
	for i in range(n):
		if B[i] != -1:
			continue
		for j in range(indexb, N):
			if TB[j]:
				TB[j] = False
				indexb = j + 1
				B[i] = j
				break
	indexa = 0
	TA = [True] * N
	for i in range(n):
		TA[B[i]] = False
		for j in range(indexa, N):
			if TA[j]:
				if A[i] != j:
					print(-1)
					return
				indexa = j
				break
	print(' '.join(map(str, B)))
main()


import sys
import math
from bisect import bisect_right as br
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
n = int(input())
arr = int_arr()
s = set(arr)
arr.insert(0, arr[0])
ans = []
p = 0
x = 0
ind = 0
for i in range(1, n + 1):
	if arr[i] != arr[i - 1]:
		ans.append(arr[i - 1])
	else:
		while ind in s:
			ind += 1
		ans.append(ind)
		ind += 1
print(*ans)


n = int(input())
a = list(map(int, input().split()))

def ehab(n, a):
	set_a = set(a)
	b = []
	ans = []
	for i in range(n + 1):
		if i not in set_a:
			b.append(i)
	index_b = 0
	ans.append(b[0])
	index_b += 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans.append(a[i - 1])
		else:
			ans.append(b[index_b])
			index_b += 1
	return ans
print(' '.join(map(str, ehab(n, a))))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
sol = [-1] * n
touse = list(range(n + 1))
if a[0] == 1:
	sol[0] = 0
	touse[0] = -1
for i in range(1, n):
	if a[i] > a[i - 1]:
		sol[i] = a[i - 1]
		touse[a[i - 1]] = -1
j = 0
touse[a[-1]] = -1
for i in range(n):
	if sol[i] == -1:
		while touse[j] == -1:
			j += 1
		sol[i] = touse[j]
		j += 1
print(*sol)


n = int(input())
A = list(map(int, input().split()))
z = True
for i in range(len(A)):
	if A[i] > i + 1:
		z = False
		break
if not z:
	print(-1)
else:
	C = []
	B = [-10]
	for i in range(1, len(A)):
		if A[i] != A[i - 1]:
			B.append(A[i - 1])
			C.append(A[i - 1])
		else:
			B.append(-10)
	C.append(A[-1])
	C.append(10 ** 18)
	q = 0
	X = 0
	for i in range(len(B)):
		if B[i] == -10:
			while X == C[q]:
				q += 1
				X += 1
			B[i] = X
			X += 1
	print(*B)


def solve_test_case(t):
	n = int(input())
	a = parse_array(int)
	a_set = set(a)
	b = []
	b_set = set()
	mex = 0
	max_b = -1

	def add_to_b(v):
		nonlocal b
		nonlocal b_set
		nonlocal mex
		nonlocal max_b
		b.append(v)
		b_set.add(v)
		max_b = max(max_b, v)
		if v == mex:
			while mex in b_set:
				mex += 1
	if a[0] == 1:
		add_to_b(0)
	elif a[0] > 1:
		print(-1)
		return
	else:
		i = 1
		while True:
			if i not in a_set:
				add_to_b(i)
				break
			i += 1
	possible = True
	for i in range(1, n):
		if a[i] > a[i - 1]:
			add_to_b(a[i - 1])
			if mex != a[i]:
				possible = False
				break
		else:
			v = max_b + 1
			while True:
				if v not in a_set:
					add_to_b(v)
					break
				v += 1
	if possible:
		print(' '.join(list(map(str, b))))
	else:
		print(-1)

def parse_array(f):
	return list(map(f, input().split()))
solve_test_case(0)


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math, itertools

def solve():
	N = getInt()
	A = getInts()
	B = []
	A_dict = {}
	for j in range(N):
		A_dict[A[j]] = j
	allowed_nums = [j for j in range(3 * N // 2, -1, -1) if j not in A_dict]
	for j in range(N):
		if A[j] > j + 1:
			return -1
		B.append(allowed_nums.pop())
		if A_dict[A[j]] == j:
			allowed_nums.append(A[j])
	print(*B)
solve()


from collections import deque
import sys
N = int(input())
A = [int(_) for _ in input().split()]
jokers = deque()
B = [-1] * N
current = 0
for (i, el) in enumerate(A):
	jokers.append(i)
	if el != current:
		for j in range(el - current):
			if not jokers:
				print(-1)
				sys.exit(0)
			p = jokers.pop()
			if A[p] == current + j:
				print(-1)
				sys.exit(0)
			else:
				B[p] = current + j
		current = el
while jokers:
	current += 1
	p = jokers.pop()
	B[p] = current
print(' '.join(map(str, B)))


def solve(arr):
	n = len(arr)
	for (a, b) in zip(arr, arr[1:]):
		if b - a < 0:
			return [-1]
	if any((a > i + 1 for (i, a) in enumerate(arr))):
		return [-1]
	seen = [False] * (n + 5)
	for a in arr:
		seen[a] = True
	res = [0] * n
	cur = 0
	for i in range(n):
		if i and arr[i] > arr[i - 1]:
			res[i] = arr[i - 1]
		else:
			while seen[cur]:
				cur += 1
			res[i] = cur
			cur += 1
	return res
input()
arr = list(map(int, input().split()))
print(*solve(arr))


n = int(input())
list1 = list(map(int, input().split()))
list2 = list()
visited = list()
for i in range(n):
	list2.append(-1)
for i in range(100001):
	visited.append(-1)
f = 0
for i in range(n):
	if list1[i] > i + 1:
		f = 1
		break
	visited[list1[i]] = 1
not_v = list()
for i in range(100001):
	if visited[i] == -1:
		not_v.append(i)
for i in range(1, n):
	if list1[i] != list1[i - 1]:
		list2[i] = list1[i - 1]
j = 0
for i in range(n):
	if list2[i] == -1:
		list2[i] = not_v[j]
		j += 1
print(*list2)


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
vis = [0] * (n + 1)
b = [-1] * n
for i in range(1, n):
	if arr[i] != arr[i - 1]:
		vis[arr[i - 1]] = 1
		b[i] = arr[i - 1]
k = 0
vis[arr[-1]] = 1
for i in range(n):
	if b[i] == -1:
		while vis[k] == 1:
			k += 1
		b[i] = k
		k += 1
print(*b)


n = int(input())
l = list(map(int, input().split()))
x = 1
prev = 0
s = set(l)
res = []
for i in l:
	if i != prev:
		res.append(prev)
		prev = i
	else:
		while x in s:
			x += 1
		res.append(x)
		x += 1
print(*res)


from heapq import heappush, heappop
n = int(input())
arr = [int(i) for i in input().split()]
toAdd = []
for i in range(n - 1):
	if arr[i] != arr[i + 1]:
		for m in range(arr[i] + 1, arr[i + 1]):
			heappush(toAdd, m)
out = [-1] * n
if arr[0] == 1:
	out[0] = 0
for i in range(1, n):
	if arr[i - 1] != arr[i]:
		out[i] = arr[i - 1]
last = 1000000
for i in range(n):
	if out[i] == -1:
		if len(toAdd) != 0:
			last = heappop(toAdd)
		out[i] = last
print(*out)


from collections import defaultdict
n = int(input())
a = [int(X) for X in input().split()]
a = a[::-1]
x = [-1 for i in range(n)]
for i in a:
	if i > n:
		print(-1)
		exit()
p = defaultdict(lambda : 0)
p[a[0]] = 1
j = 0
for i in range(n - 1):
	if a[i] != a[i + 1]:
		x[i] = a[i + 1]
		p[a[i + 1]] = 1
j = n
for i in range(n):
	while p[j] == 1:
		j -= 1
	if x[i] == -1:
		x[i] = j
		j -= 1
print(*x[::-1])


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	arr = list_input()
	if arr[0] != 0 and arr[0] != 1:
		print(-1)
		return
	ans = []
	temp = list(set(arr))
	if len(temp) == 1:
		if temp[0] == 0:
			print('1 ' * n)
			return
		elif temp[0] == 1:
			print('0 ' * n)
			return
	elif len(temp) == 2:
		if temp[0] == 0 and temp[1] == 1:
			i = 0
			while i < n and arr[i] == 0:
				print(2, end=' ')
				i += 1
			while i < n and arr[i] == 1:
				print(0, end=' ')
				i += 1
			print()
			return
	num = [False] * n
	remain = n
	i = 0
	if arr[0] == 1:
		remain -= 1
		prev = 1
		num[0] = True
		ans.append(0)
		i += 1
		while i < n and arr[i] == 1:
			ans.append(-1)
			i += 1
	else:
		prev = 0
		while i < n and arr[i] == 0:
			ans.append(-1)
			i += 1
	while i < n:
		remain -= 1
		num[prev] = True
		ans.append(prev)
		prev = arr[i]
		if i + 1 < arr[i]:
			print(-1)
			return
		j = i + 1
		while j < n and arr[j] == arr[i]:
			ans.append(-1)
			j += 1
		i = j
	if not num[1]:
		remain -= 1
		num[1] = True
		ans[0] = 1
	if n > arr[-1]:
		remain -= 1
		num[arr[-1]] = True
	indx = 0
	for i in range(n):
		if ans[i] == -1:
			while indx < n and num[indx]:
				indx += 1
			ans[i] = indx
			if remain > 1:
				num[indx] = True
				remain -= 1
	print(*ans)
t = 1
for _ in range(t):
	solve()


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
krish = 1000
raj = krish * 90
r = krish - 90
n = int(input())
l = list([int(x) for x in input().split()])
b = [-1] * n
s = set(l)
s1 = set()
for i in range(n + 1):
	if i not in s:
		s1.add(i)
for i in range(1, n):
	if l[i] != l[i - 1]:
		b[i] = l[i - 1]
bl = list(s1)
k = 0
for i in range(n):
	if b[i] == -1:
		b[i] = bl[k]
		k += 1
print(*b)
r -= 10


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	d = [-1] * n
	done = [False] * (n + 1)
	s = 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			continue
		d[i + 1] = a[i]
		done[a[i]] = True
		s = i + 1
	d[0] = -1 if a[0] == 0 else 0
	if a[0] == 1:
		done[0] = True
	done[a[-1]] = True
	fin = []
	for i in range(n, -1, -1):
		if not done[i]:
			fin.append(i)
	for i in range(n):
		if d[i] == -1:
			d[i] = fin.pop()
	for h in d:
		print(h, end=' ')
	print('')


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = [int(c) for c in input().split()]
b = [-1 for i in range(n)]
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
j = 0
s = set(a)
for i in range(n):
	if b[i] == -1:
		while j in s:
			j += 1
		b[i] = j
		j += 1
print(' '.join([str(c) for c in b]))


from sys import stdin
t = 1
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	flg = True
	res = list()
	places = list()
	if a[0] not in (0, 1):
		flg = False
	p = a[0]
	cur = 0
	if p:
		res.append(0)
		cur += 1
	for i in range(1, n):
		if a[i] > i + 1:
			flg = False
			break
		if a[i] != p:
			for j in range(p + 1, a[i]):
				if cur >= i:
					if not places:
						flg = False
						break
					x = places.pop()
					res[x] = j
				else:
					res.append(j)
					cur += 1
			while cur < i:
				res.append(1000000)
				places.append(cur)
				cur += 1
			res.append(p)
			cur += 1
		p = a[i]
	while cur < n:
		res.append(1000000)
		cur += 1
	if flg:
		print(' '.join([str(x) for x in res]))
	else:
		print(-1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	d = {}
	for ai in a:
		if ai not in d:
			d[ai] = 0
		d[ai] += 1
	c = []
	i = 0
	while len(c) < n:
		if i not in d:
			c.append(i)
		i += 1
	b = [0] * n
	k = 0
	for i in range(n):
		if i == 0:
			b[i] = c[k]
			k += 1
		elif a[i] != a[i - 1]:
			b[i] = a[i - 1]
		else:
			b[i] = c[k]
			k += 1
	return b

def main():
	n = ri()
	a = ria()
	res = solve(n, a)
	if res == -1:
		wi(-1)
	else:
		wia(res)
main()


from sys import stdin, stdout
import math
import bisect

def main():
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	for (i, x) in enumerate(l):
		if x > i + 1:
			print(-1)
			return
	l = [0] + l
	missing = list(set(list(range(n + 1))) - set(l))[::-1]
	ans = []
	for i in range(1, n + 1):
		if l[i] == l[i - 1]:
			ans.append(missing.pop())
		else:
			ans.append(l[i - 1])
	stdout.write(' '.join(map(str, ans)) + '\n')
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	need = a[-1] - 1
	done = set()
	million = 10 ** 6
	for i in range(n - 1, 0, -1):
		if a[i] == a[i - 1]:
			while True:
				if need in done:
					need -= 1
				elif need < a[i]:
					b.append(million)
					break
				else:
					b.append(need)
					done.add(need)
					break
		else:
			b.append(a[i - 1])
			done.add(a[i - 1])
	if a[0] == 0:
		while True:
			if need in done:
				need -= 1
			elif need < a[0]:
				b.append(million)
				break
			else:
				b.append(need)
				done.add(need)
				break
	else:
		b.append(0)
	b.reverse()
	print(*b)
main()


def solve(n, a):
	b = [None] * n
	u = set(a)
	for i in range(1, n):
		if a[i] > a[i - 1]:
			b[i] = a[i - 1]
		if a[i] > i + 1:
			return -1
	j = 0
	for i in range(n):
		if b[i] is not None:
			continue
		while j in u:
			j += 1
		b[i] = j
		u.add(j)
	return ' '.join(map(str, b))
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))


n = int(input())
a = [0] + list(map(int, input().split(' ')))
b = [100002] * (n + 1)
index = 1
for i in range(n):
	if a[i] != a[i + 1]:
		b[i + 1] = a[i]
		for j in range(a[i] + 1, a[i + 1]):
			while b[index] != 100002:
				index += 1
			b[index] = j
print(' '.join(list(map(str, b[1:]))))


n = int(input())
a = [int(f) for f in input().split()]
m = set(a)
b = []
p = set((f for f in range(0, a[n - 1] + 1)))
p = p - m
p = list(p)
g = 0
l = 0
cur = 0
if cur < len(p):
	fl = True
else:
	fl = False
for i in range(n):
	if i == 0:
		if a[i] == 0:
			if fl:
				b.append(p[cur])
				cur += 1
			else:
				b.append(a[n - 1] + 10)
		else:
			b.append(0)
			if p[cur] == 0:
				cur += 1
		if cur == len(p):
			fl = False
	else:
		if a[i] == a[i - 1]:
			if fl:
				b.append(p[cur])
				cur += 1
			else:
				b.append(a[n - 1] + 10)
		else:
			b.append(a[i - 1])
		if cur == len(p):
			fl = False
for el in b:
	print(el, end=' ')


n = int(input())
mt = list(map(int, input().split()))
ans = [-1] * n
dup = set(mt)
sec = set([int(x) for x in range(n + 1)])
sec = sec.difference(dup)
sec = list(sec)
ans[0] = sec[0]
sec.remove(sec[0])
for i in range(1, n):
	if mt[i - 1] != mt[i]:
		ans[i] = mt[i - 1]
	else:
		ans[i] = sec[0]
		sec.remove(sec[0])
print(*ans)


n = int(input())
a = list(map(int, input().split()))
v1 = [False] * (n + 1)
s1 = sorted(list(set(a)), reverse=True)
for i in s1:
	v1[i] = True
tmp = 0
b = [0] * n
flag = True
for i in range(n):
	if len(s1) > 0 and a[i] > s1[-1]:
		b[i] = s1[-1]
		s1.pop()
	elif flag == True:
		if tmp == a[i] or v1[tmp] == True:
			while True:
				tmp += 1
				if tmp > n:
					flag = False
					b[i] = n + 5
					break
				if v1[tmp] == False:
					b[i] = tmp
					tmp += 1
					break
		else:
			b[i] = tmp
			tmp += 1
	else:
		b[i] = n + 5
print(*b)


from sys import stdin, stdout, setrecursionlimit
for _ in range(1):
	n = int(input())
	a = [int(i) for i in input().split()]
	f = True
	ans = [-1] * n
	ok = [False] * (n + 1)
	for i in range(n):
		if a[i] > i + 1 or a[i] > a[min(i + 1, n - 1)]:
			f = False
			break
		ok[a[i]] = True
	if not f:
		print(-1)
		continue
	nums = []
	curi = 0
	for i in range(n + 1):
		if not ok[i]:
			nums.append(i)
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			ans[i + 1] = a[i]
	for i in range(n):
		if ans[i] == -1:
			ans[i] = nums[curi]
			curi += 1
	print(*ans)


n = int(input())
arr = list(map(int, input().split()))
arr1 = sorted(list(set(arr))) + [1000000]
b = []
min_val_not_vis = 0
vis = [0] * 1000001
j = 0
k = -1
for i in arr:
	vis[i] = 1

def get_nex_val():
	global k
	k += 1
	while k < 1000001:
		if vis[k]:
			k += 1
		else:
			break
for i in range(n):
	if arr[i] != arr1[j]:
		j += 1
		b.append(arr1[j - 1])
	else:
		get_nex_val()
		b.append(k)
ans = True
vis = [0] * 1000001
k = 0
for i in range(n):
	vis[b[i]] = 1
	if vis[k]:
		while True:
			if vis[k]:
				k += 1
			else:
				break
	if arr[i] != k:
		ans = False
		break
if ans:
	print(*b)
else:
	print(-1)


input()
nums = list(map(int, input().split()))
nums_set = set(nums)
complement = (x for x in range(2 * len(nums)) if x not in nums_set)
b = []
for (i, a) in enumerate(nums):
	if a > i + 1:
		print(-1)
		exit()
	if i and a != nums[i - 1]:
		b.append(nums[i - 1])
	else:
		b.append(next(complement))
print(*b)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
n = int(input().strip())
a = rl()
s = list(set(a))
s.sort()
d = defaultdict(lambda : -1)
ans = []
prev = 0
for i in s:
	d[i] = 1
f = 1
prev = -1
for i in range(0, n):
	if i != 0 and a[i] != a[i - 1]:
		ans.append(a[i - 1])
		continue
	while 1:
		prev = prev + 1
		if d[prev] == 1:
			continue
		else:
			break
	ans.append(prev)
	if a[i] - prev > 1:
		f = 0
		break
if f:
	mx = 0
	for i in range(0, n):
		mx = max(ans[i], mx)
		if a[i] - mx > 1:
			print(-1)
			exit()
	print(*ans)
else:
	print(-1)


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(n,) = rl()
a = rl()
a_set = set(a)
free = 0
prev = 0
b = []
for cur in a:
	if cur != prev:
		b.append(prev)
		if free == prev:
			free += 1
		prev = cur
	else:
		while free in a_set:
			free += 1
		b.append(free)
		free += 1
print(*b)


n = int(input())
ls = list(map(int, input().split()))
cc = set()
res = [-1] * n
for i in range(n):
	if i > 0 and ls[i - 1] != ls[i]:
		res[i] = ls[i - 1]
		cc.add(ls[i - 1])
cc.add(ls[-1])
(p, cv) = (0, 0)
while p < n:
	while cv in cc:
		cv += 1
	while p < n and res[p] != -1:
		p += 1
	if p < n:
		res[p] = cv
		cv += 1
print(*res)


n = int(input())
lis = list(map(int, input().split()))
maxi = lis[-1]
k = n - 1
flag = 1
ans = []
if maxi > n:
	flag = -1
if flag == -1:
	print(-1)
else:
	xtra = 0
	points = []
	if lis[0] == 0:
		ans.append(maxi + 1)
		xtra = xtra + 1
		points.append(0)
	elif lis[0] == 1:
		ans.append(0)
	else:
		flag = -1
	if flag != -1:
		for i in range(1, n):
			l = lis[i]
			if l == lis[i - 1]:
				ans.append(maxi + 1)
				xtra = xtra + 1
				points.append(i)
			elif lis[i] == lis[i - 1] + 1:
				ans.append(lis[i - 1])
			else:
				dif = lis[i] - lis[i - 1] - 1
				if dif > xtra:
					flag = -1
					break
				else:
					for j in range(lis[i - 1] + 1, lis[i]):
						ans[points[0]] = j
						points.pop(0)
						xtra = xtra - 1
					ans.append(lis[i - 1])
	if flag == -1:
		print(-1)
	else:
		print(*ans, sep=' ')


n = int(input())
a = list(map(int, input().split()))
k = 0
b = [0] * n
s = set(a)
t = [False for i in range(n)]
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		t[i] = True
m = 0
for i in range(n):
	if not t[i]:
		while True:
			if m not in s:
				b[i] = m
				break
			else:
				m += 1
		m += 1
for i in b:
	print(i, end=' ')


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 6 - 1
ans = [INF] * n
l = 0
if a[0] == 1:
	ans[0] = 0
for i in range(n - 1):
	if i + 1 < a[i]:
		print(-1)
		exit()
	if a[i] < a[i + 1]:
		if i + 2 < a[i + 1]:
			print(-1)
			exit()
		ans[i + 1] = a[i]
		min_num = a[i] + 1
		max_num = a[i + 1] - 1
		while min_num <= max_num:
			if ans[l] == INF:
				ans[l] = min_num
				min_num += 1
			l += 1
print(*ans)


import sys

def read():
	return int(input())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()

def solve():
	n = read()
	a = get_array()
	a = [0] + a
	b = [-1 for i in range(n + 1)]
	used = [False for i in range(n + 1)]
	for i in range(1, n + 1):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			used[b[i]] = True
	used[a[n]] = True
	m = 0
	for i in range(1, n + 1):
		if b[i] == -1:
			while used[m]:
				m += 1
			b[i] = m
			used[m] = True
	for i in range(1, n + 1):
		print('%d ' % b[i], end='')
	print()
solve()


n = int(input())
a = list(map(int, input().split()))
value = n
used = set()
b = [-1] * n
for i in range(n - 1, -1, -1):
	used.add(a[i])
	if i > 0 and a[i] > a[i - 1]:
		b[i] = a[i - 1]
	else:
		while value >= 0 and value in used:
			value -= 1
		if value >= 0:
			b[i] = value
			if value > 0:
				value -= 1
		else:
			b[i] = n
used = [0] * (n + 1)
mex = 0
for i in range(n):
	used[b[i]] = 1
	while used[mex]:
		mex += 1
	if a[i] != mex:
		print(-1)
		break
else:
	print(*b)


n = int(input())
l = list(map(int, input().split()))
s = set(l)
(chk, mex, nxt, last) = (True, l[0], 0, -1)
final = []
for i in range(n):
	if l[i] > i + 1:
		chk = False
		break
	elif l[i] == last or last == -1:
		while nxt in s:
			nxt += 1
		last = l[i]
		final.append(nxt)
		nxt += 1
	else:
		s.remove(last)
		final.append(mex)
		mex = l[i]
		nxt = max(nxt, mex)
		last = l[i]
print(*(final if chk else -1))


import heapq
(n, a, b) = (int(input()), list(map(int, input().split())), [0] * 200000)
for i in range(n):
	b[a[i]] = 1
hp = [i for i in range(n + 1) if not b[i]]
heapq.heapify(hp)
for i in range(n - 1):
	print(heapq.heappop(hp), end=' ')
	if a[i] < a[i + 1]:
		heapq.heappush(hp, a[i])
print(heapq.heappop(hp))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = [1000000] * n
	p = 0
	st = []
	for (i, x) in enumerate(a):
		st.append(i)
		if p < x:
			while st and p < x:
				b[st.pop()] = p
				p += 1
	print(' '.join(map(str, b)))
main()


n = int(input())
arr = [x for x in map(int, input().split(' '))]
b = []
last_seen = dict()
no_use = set()
for (i, v) in enumerate(arr):
	last_seen[v] = i
	no_use.add(v)
to_use = [x for x in range(n, -1, -1) if x not in no_use]
for (i, v) in enumerate(arr):
	b.append(to_use.pop())
	if last_seen[v] == i:
		to_use.append(v)
for v in b:
	print(v, end=' ')
print()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scan_int()
	a = read_list()
	s = set(a)
	now = 1
	p = 0
	for i in range(n):
		if a[i] != p:
			print(p, end=' ')
			p = a[i]
			if now == a[i]:
				now += 1
		else:
			while now in s:
				now += 1
			print(now, end=' ')
			now += 1
	print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
solve()


from collections import defaultdict, Counter
from math import sqrt, log10, log2, log, gcd, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import combinations, combinations_with_replacement
import sys, io, os
input = lambda : sys.stdin.readline().encode()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
mod = 10 ** 9 + 7
inf = float('inf')

def get_list():
	return [int(i) for i in input().split()]
yn = lambda a: print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = 1
for i in range(t):
	n = int(input())
	l = [0] + get_list()
	lsort = sorted(l)
	ans = [0] * (n + 1)
	stack = []
	initial = 0
	dict = defaultdict(int)
	for i in range(1, n + 1):
		if l[i] > l[i - 1]:
			ans[i] = l[i - 1]
			dict[l[i - 1]] = 1
			while initial < l[i]:
				if initial in dict:
					initial += 1
					continue
				ans[stack.pop()] = initial
				initial += 1
		else:
			stack.append(i)
			ans[i] = 10 ** 6
	print(*ans[1:])


from collections import deque
import sys
n = int(input())
l = [-1 for i in range(n)]
a = [int(i) for i in input().split()]
maxx = max(a)
pos = deque()
flag = 1
for i in range(n):
	if a[i] > i + 1:
		flag = 0
if a[0] == 1:
	l[0] = 0
else:
	pos.append(0)
for i in range(1, n):
	if a[i] == a[i - 1]:
		pos.append(i)
		continue
	else:
		l[i] = a[i - 1]
		for j in range(a[i - 1] + 1, a[i]):
			if len(pos) == 0:
				flag = 0
				break
			x = pos.popleft()
			l[x] = j
if flag:
	for i in pos:
		l[i] = maxx + 1
	for i in l:
		print(i, end=' ')
	print
else:
	print(-1)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = 1
for tc in range(t):
	n = int(stdin.readline())
	ar = list(map(int, stdin.readline().split()))
	resar = [-1 for _ in range(n)]
	res = 1
	if ar[0] > 1:
		res = -1
	else:
		if ar[0] == 1:
			resar[0] = 0
			lastval = 1
			curmex = 1
			curnext = 1
			nextskipi = 0
		else:
			i = 1
			while i < n and ar[i] <= ar[i - 1] + 1:
				i += 1
			resar[0] = ar[i - 1] + 1
			lastval = 0
			curmex = 0
			curnext = resar[0] + 1
			nextskipi = 0
		while nextskipi < n - 1 and ar[nextskipi] < curnext:
			nextskipi += 1
		while ar[nextskipi] == curnext:
			curnext += 1
			while nextskipi < n - 1 and ar[nextskipi] < curnext:
				nextskipi += 1
		sofar = set()
		sofar.add(resar[0])
		for i in range(1, n):
			if ar[i] == lastval:
				resar[i] = curnext
				sofar.add(curnext)
				curnext += 1
				while nextskipi < n - 1 and ar[nextskipi] < curnext:
					nextskipi += 1
				while ar[nextskipi] == curnext:
					curnext += 1
					while nextskipi < n - 1 and ar[nextskipi] < curnext:
						nextskipi += 1
			else:
				resar[i] = curmex
				sofar.add(curmex)
				while curmex in sofar:
					curmex += 1
			if curmex != ar[i]:
				res = -1
				break
			lastval = ar[i]
	if res == -1:
		stdout.write(str(res) + '\n')
	else:
		for val in resar:
			stdout.write(str(val) + ' ')
		stdout.write('\n')


import sys
input = sys.stdin.readline
from collections import *
from heapq import *
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] > i + 1:
		print(-1)
		exit()
s = set(a)
pq = []
for i in range(10 ** 6 + 1):
	if i not in s:
		heappush(pq, i)
ans = []
for i in range(n):
	if i >= 1 and a[i] > a[i - 1]:
		heappush(pq, a[i - 1])
	ans.append(heappop(pq))
print(*ans)


import heapq
n = int(input())
list1 = list(map(int, input().split()))
vist = [0] * 100002
for i in range(len(list1)):
	vist[list1[i]] += 1
f = 0
for i in range(len(list1)):
	if list1[i] > i + 1:
		f = 1
		break
if f == 1:
	print(-1)
else:
	p = []
	for i in range(len(vist)):
		if vist[i] == 0:
			p.append(i)
	heapq.heapify(p)
	ans = []
	for i in range(n):
		t = heapq.heappop(p)
		ans.append(t)
		vist[list1[i]] -= 1
		if vist[list1[i]] == 0:
			heapq.heappush(p, list1[i])
	print(*ans)


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for j in range(0, n):
		l1.append(-1)
	f = []
	for j in range(0, 1000000):
		f.append(-1)
	f[l[0]] = 1
	for j in range(1, n):
		if l[j - 1] != l[j]:
			l1[j] = l[j - 1]
			f[l[j - 1]] = 1
		f[l[j]] = 1
	k = 0
	for j in range(0, n):
		if l1[j] == -1:
			while k <= 1000000:
				if f[k] == -1:
					f[k] = 1
					l1[j] = k
					break
				k += 1
	print(*l1)
t = 1
for i in range(0, t):
	main()


import heapq
n = int(input())
a = list(map(int, input().split()))
fl = True
r = [0] * (n + 1)
s = set()
for i in range(n):
	s.add(a[i])
for i in s:
	r[i] = 1
t = []
for i in range(n + 1):
	if r[i] == 0:
		t.append(i)
heapq.heapify(t)
x = [-1] * n
for i in range(n - 1):
	if a[i] != a[i + 1]:
		x[i + 1] = a[i]
for i in range(n):
	if x[i] == -1:
		k = heapq.heappop(t)
		x[i] = k
print(*x)


import math

def findholes(arr):
	holes = [False] * 100005
	for a in arr:
		holes[a] = True
	ret = []
	for (i, h) in enumerate(holes):
		if h == False:
			ret.append(i)
	return ret

def findb(arr):
	holes = findholes(arr)
	holes = holes[::-1]
	b_array = []
	for (i, a) in enumerate(arr):
		if i > 0 and arr[i] > arr[i - 1]:
			holes.append(arr[i - 1])
		currhole = holes.pop(-1)
		b_array.append(currhole)
		if a < 0:
			return []
		if a != 0:
			if len(holes) > 0:
				if holes[-1] <= a - 1:
					return []
	return b_array
n = int(input())
a = [int(x) for x in input().split(' ')]
ans = findb(a)
if len(ans) == 0:
	print(-1)
else:
	print(' '.join([str(x) for x in ans]))


n = int(input())
l1 = list(map(int, input().split()))
s = set(l1)
s4 = list(s)
l = len(s4)
i = 0
m = 0
k = 0
l2 = [-1] * n
while i != n - 1:
	if l2[i] == -1:
		while k < l and m == s4[k]:
			m += 1
			k += 1
		l2[i] = m
		m += 1
	if l1[i + 1] > l1[i]:
		l2[i + 1] = l1[i]
	i += 1
if l2[i] == -1:
	while k < l and m == s4[k]:
		m += 1
		k += 1
	l2[i] = m
print(*l2)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
test_case = 1
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	b = [-1] * n
	v = [0] * (2 * n + 3)
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
		v[a[i]] = 1
	v[a[0]] = 1
	j = 0
	for i in range(n):
		if b[i] == -1:
			while v[j]:
				j += 1
			b[i] = j
			j += 1
	print(*b)


n = int(input())
a = [int(x) for x in input().split()]
a.insert(0, 0)
ans = [-1] * n
used = [False] * (n + 1)
for i in range(1, n + 1):
	if a[i] != a[i - 1]:
		ans[i - 1] = a[i - 1]
		used[a[i - 1]] = 1
used[a[n]] = 1
cur = 0
for i in range(n):
	if ans[i] == -1:
		while used[cur]:
			cur += 1
		ans[i] = cur
		used[cur] = 1
print(*ans)


def read_ints():
	return list(map(int, input().split()))
(n,) = read_ints()
a = read_ints()
b = [-1] * n
used = set(a)
current = 0
j = 1
for i in range(n):
	if a[i] != current:
		b[i] = current
		current = a[i]
		if current > i + 1:
			print(-1)
			break
	else:
		while j in used:
			j += 1
		b[i] = j
		j += 1
else:
	print(*b)


def main():
	N = int(input())
	(*A,) = map(int, input().split())
	for (i, a) in enumerate(A):
		if i + 1 < a:
			print(-1)
			return
	else:
		Us = set(range(N + 1)) - set(A)
		U = sorted(Us)
		lU = len(U)
		ui = 0
		ans = []
		pre = A[0]
		for (i, a) in enumerate(A):
			if pre != a:
				ans.append(pre)
			else:
				if ui >= lU:
					print(-1)
					return
				ans.append(U[ui])
				ui += 1
			pre = a
		print(*ans)
main()


import sys
input = sys.stdin.buffer.readline
n = int(input())
A = [int(x) for x in input().split()]
B = [0 for _ in range(n)]
aValues = set(A)
prevVal = 0
possible = True
nextValue = 1
while nextValue in aValues:
	nextValue += 1
for i in range(n):
	if A[i] != prevVal:
		if A[i] - 1 > i:
			possible = False
			break
		B[i] = prevVal
		prevVal = A[i]
	else:
		B[i] = nextValue
		nextValue += 1
		while nextValue in aValues:
			nextValue += 1
if possible == True:
	print(' '.join([str(x) for x in B]))
else:
	print('-1')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	if A[-1] == 0:
		B = [1] * n
		print(' '.join((str(num) for num in B)))
		return
	for i in range(n):
		if A[i] > i + 1:
			print(-1)
			return
	l = A[-1]
	visited = [0] * l
	B = [-1] * n
	if A[0] >= 2:
		print(-1)
		return
	if A[0] == 1:
		B[0] = 0
		visited[0] = 1
	for i in range(1, n):
		if A[i] != A[i - 1]:
			B[i] = A[i - 1]
			visited[A[i - 1]] = 1
	i = 0
	for j in range(l):
		if visited[j]:
			continue
		while B[i] != -1:
			i += 1
			if i >= n:
				print(-1)
				return
		B[i] = j
	for i in range(n):
		if B[i] == -1:
			B[i] = l + 1
	print(' '.join((str(num) for num in B)))
f()


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
marked = [False] * (2 * n + 1)
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		marked[b[i]] = True
marked[a[n - 1]] = True
m = 0
for i in range(n):
	while marked[m]:
		m += 1
	if b[i] == -1:
		b[i] = m
		marked[b[i]] = True
	print(b[i], end=' ')


import math
n = int(input())
a = [int(i) for i in input().split()]
d = False
for i in range(n):
	if a[i] > i + 1 or (i < n - 1 and a[i + 1] < a[i]):
		print(-1)
		d = True
		break
if not d:
	out = [-1] * n
	for i in range(1, n):
		if a[i] != a[i - 1]:
			out[i] = str(a[i - 1])
		else:
			out[i] = -1
	next_ = n
	seen = {a[-1]}
	for i in range(n - 1, -1, -1):
		seen.add(a[i])
		if out[i] == -1:
			while next_ in seen:
				next_ -= 1
			out[i] = str(next_)
			next_ -= 1
	print(' '.join(out))


n = int(input())
a = [int(x) for x in input().split(' ')]
a_dict = {}
for item in a:
	if item in a_dict.keys():
		a_dict[item] += 1
	else:
		a_dict[item] = 1
m = 0
ans = []
skip_print = False
for i in range(n):
	if a[i] > i + 1:
		print(-1)
		skip_print = True
		break
	if i > 0 and a[i] != a[i - 1]:
		ans.append(a[i - 1])
	else:
		while m in a_dict.keys():
			m += 1
		ans.append(m)
		m += 1
if not skip_print:
	print(*ans)


n = int(input())
l = list(map(int, input().strip().split()))
b = [-1 for a in range(0, n)]
for i in range(0, n - 1):
	if l[i] != l[i + 1]:
		b[i + 1] = l[i]
t = set([j for j in range(0, 10 ** 6 + 1)]) - set(l)
t = list(t)
t.sort()
c = 0
for i in range(0, n):
	if b[i] == -1:
		b[i] = t[c]
		c += 1
print(' '.join((str(e) for e in b)))


import sys
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [-1] * n
used = set(a)
for i in range(n):
	if a[i] != a[i + 1]:
		ans[i] = a[i]
	if a[i + 1] > i + 1:
		print(-1)
		exit(0)
curr = 0
for i in range(n):
	if ans[i] == -1:
		curr += 1
		while curr in used:
			curr += 1
		ans[i] = curr
pprint(ans)


n = int(input())
data = list(map(int, input().split()))
no = False
for i in range(n):
	if i + 1 < data[i]:
		no = True
my_set = set()
if no:
	print(-1)
else:
	for x in data:
		my_set.add(x)
	count = 0
	while count in my_set:
		count += 1
	print(count, end=' ')
	my_set.add(count)
	for i in range(1, n):
		if data[i] != data[i - 1]:
			print(data[i - 1], end=' ')
			continue
		while count in my_set:
			count += 1
		print(count, end=' ')
		my_set.add(count)
	print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
vals = list(map(int, input().split()))
noreps1 = set(vals)
noreps = list(noreps1)
noreps.sort()
maxy = vals[-1]
miny = vals[0]
posi = True
minsofar = 0
broke = False
for j in range(n):
	if j + 1 < vals[j]:
		broke = True
		break
if broke == True:
	print(-1)
else:
	outy = ['x'] * n
	cv = 0
	minsofar = 0
	if len(noreps1) >= 2:
		for s in range(n):
			if cv + 1 <= len(noreps) - 1 and vals[s] == noreps[cv + 1]:
				outy[s] = str(noreps[cv])
				cv += 1
	for s in range(n):
		if outy[s] == 'x':
			while minsofar in noreps1:
				minsofar += 1
			outy[s] = str(minsofar)
			minsofar += 1
	print(' '.join(outy))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
import heapq
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 1000000007

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	n = int(inp())
	a = lis()
	m = max(a)
	for i in range(0, n):
		if i >= a[i] - 1:
			continue
		else:
			print(-1)
			return
	b = [-1] * n
	nta = [False] * (m + 1)
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
	s = list(set(b))
	for i in s:
		nta[i] = True
	if a[0] == 0:
		curr = 1
	else:
		curr = 0
	toadd = []
	for i in range(0, m + 1):
		if nta[i] == False:
			toadd.append(i)
	for i in range(m + 1, 10 ** 6 + 1):
		toadd.append(i)
	j = 0
	for i in range(0, n):
		if b[i] == -1:
			b[i] = toadd[j]
			j += 1
	print(*b)
testcase(1)


import os
import sys
from io import BytesIO, IOBase
import threading

def main():
	for _ in range(1):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = [-1] * n
		t = [0] * 10 ** 6
		t[arr[-1]] = 1
		for i in range(1, n):
			if arr[i] != arr[i - 1]:
				ans[i] = arr[i - 1]
				t[arr[i - 1]] = 1
		bi = 0
		for i in range(n):
			while t[bi] == 1:
				bi += 1
			if ans[i] == -1:
				ans[i] = bi
				bi += 1
		print(' '.join([str(i) for i in ans]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
n = read_i()
a = [read_i() for i in range(n)]
need = [i != a[-1] for i in range(n + 1)]
ans = [-1 for i in range(n)]
for i in range(n):
	if i > 0 and a[i] != a[i - 1]:
		ans[i] = a[i - 1]
		need[ans[i]] = False
j = 0
for i in range(n):
	if ans[i] == -1:
		while not need[j]:
			j += 1
		ans[i] = j
		need[j] = False
write_s(' '.join([str(x) for x in ans]))
print_ans()


import sys

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
if a[0] not in [0, 1] or a != sorted(a):
	print(-1)
else:
	boo = True
	for i in range(n):
		if a[i] > i + 1:
			boo = False
			break
	if boo == False:
		print(-1)
	else:
		b = [-1] * n
		arr = list(range(n))
		if a[-1] < n:
			arr = list(range(n + 1))
			arr.pop(a[-1])
		d = {}
		for i in arr:
			d[i] = 0
		for i in range(n - 1, 0, -1):
			if a[i] > a[i - 1]:
				b[i] = a[i - 1]
				d[a[i - 1]] = 1
		temp = 0
		for i in range(n):
			if b[i] == -1:
				while d[arr[temp]] == 1:
					temp += 1
				b[i] = arr[temp]
				temp += 1
		print(*b)


import sys
read = lambda : sys.stdin.readline()
n = int(read())
arr = list(map(int, read().split()))
result = [-1 for i in range(n)]
for i in range(n - 1, 0, -1):
	if arr[i] > arr[i - 1]:
		result[i] = arr[i - 1]
if arr[0] == 1:
	result[0] = 0
haves = set([])
free = 0
while free < n and result[free] != -1:
	free += 1
impossible = False
for i in range(1, n):
	if result[i] == -1:
		continue
	haves.add(result[i])
	for j in range(arr[i - 1], arr[i]):
		if not j in haves:
			if free > i:
				impossible = True
			result[free] = j
			haves.add(j)
			free += 1
			while free < n and result[free] != -1:
				free += 1
for i in range(n):
	if result[i] == -1:
		result[i] = 100001
if impossible:
	print(-1)
else:
	for i in range(n - 1):
		print(result[i], end=' ')
	print(result[-1])


n = int(input())
a = list(map(int, input().split()))
b = [None] * n
ind = 0
mex = 0
import sys
for i in range(n):
	if mex != a[i]:
		for j in range(mex + 1, a[i]):
			while ind < i and b[ind] != None:
				ind += 1
			if ind >= i:
				print(-1)
				sys.exit()
			b[ind] = j
		b[i] = mex
		mex = a[i]
for i in range(n):
	if b[i] == None:
		b[i] = 10 ** 6
print(*b)


no = int(input())
seq = list(map(int, input().split()))
x = 0
y = 1
t = set(seq)
for i in seq:
	if i == x:
		while y in t:
			y += 1
		print(y, end=' ')
		y += 1
	else:
		print(x, end=' ')
		x = i


t = 1
while t != 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	st = set()
	b = [-1 for _ in range(n)]
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			st.add(b[i])
	st.add(a[-1])
	m = 0
	for i in range(n):
		if b[i] == -1:
			while m in st:
				m += 1
			b[i] = m
			m += 1
	print(*b)


from sys import stdin
from collections import Counter
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
cou = Counter()
fl = 0
for val in arr:
	cou[val] += 1
see = set(arr)
if not fl:
	i = 1
	add = -1
	if arr[0] == 1:
		fin = [0]
		cou[1] -= 1
		if cou[1] == 0:
			add = 1
	else:
		fin = []
		for x in range(1, 10 ** 6):
			if x not in see:
				fin.append(x)
				break
		cou[0] -= 1
		if cou[0] == 0:
			add = 0
	se = set(fin)
	a = arr[0] + 1
	while len(fin) != n:
		if add != -1:
			fin.append(add)
			se.add(add)
			add = -1
			cou[arr[i]] -= 1
			if cou[arr[i]] == 0:
				add = arr[i]
			i += 1
			continue
		while cou.get(a) or a in se:
			a += 1
		fin.append(a)
		se.add(a)
		cou[arr[i]] -= 1
		if cou[arr[i]] == 0:
			add = arr[i]
		i += 1
	for i in fin:
		print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
flag = 1
v = [False for i in range(100001)]
for i in range(n):
	v[a[i]] = True
	if a[i] > i + 1:
		print(-1)
		flag = 0
		break
if flag == 1:
	b = [-1 for i in range(n)]
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			v[a[i - 1]] = True
	j = 0
	for i in range(n):
		if b[i] == -1:
			while b[i] == -1 and j < 100001:
				if v[j]:
					j += 1
				else:
					b[i] = j
					v[j] = True
	for i in b:
		print(i, end=' ')


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
a = 0
b = 1
mark = {i: 1 for i in A}
for i in A:
	if i == a:
		while mark.get(b, 0) == 1:
			b += 1
		print(b, end=' ')
		b += 1
	else:
		print(a, end=' ')
		a = i


n = int(input())
a = [int(j) for j in input().split(' ')]
b = [-1] * n
if a[0] > 1:
	print(-1)
else:
	if a[0] == 0:
		mex = 0
		count = 0
	else:
		mex = 1
		count = 1
		b[0] = 0
	result = 1
	for i in range(1, n):
		if a[i] != mex:
			b[i] = mex
			mex += 1
			while mex < a[i]:
				if b[count] == -1:
					b[count] = mex
					mex += 1
				while b[count] != -1:
					count += 1
					if count > i:
						if mex == a[i]:
							break
						else:
							mex = a[i]
							result = 0
							break
			if result == 0:
				break
	if result == 1:
		for i in range(n):
			if b[i] == -1:
				b[i] = mex + 1
		for i in range(n - 1):
			print(b[i], end=' ')
		print(b[-1])
	else:
		print(-1)


i_liczb = int(input())
a = [int(x) for x in input().split()]
a = [0] + a
if a[i_liczb] > i_liczb:
	print(-1)
	quit()
b = [-1 for _ in range(i_liczb + 1)]
wykorzystane = [False for _ in range(100005)]
for i in range(1, i_liczb + 1):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		wykorzystane[b[i]] = True
wykorzystane[a[i_liczb]] = True
x = 0
for i in range(1, i_liczb + 1):
	while wykorzystane[x]:
		x += 1
	if b[i] == -1:
		b[i] = x
		wykorzystane[x] = True
print(*b[1:])


from heapq import *
(n, *a) = map(int, open(0).read().split())
b = [-1] * n
unused = set(range(2 * n + 1))
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		unused.remove(a[i - 1])
unused.remove(a[-1])
hq = list(unused)
heapify(hq)
for i in range(n):
	if b[i] == -1:
		b[i] = heappop(hq)
print(*b)


n = int(input())
a = list(map(int, input().split()))
alphabet = list()
alphabet.append(a[0])
for i in range(1, n):
	if a[i] > i + 1:
		print(-1)
		exit()
	if a[i] != a[i - 1]:
		alphabet.append(a[i])
point = 0
if alphabet[point] == 0:
	point += 1
if len(alphabet) == 1:
	cur = 2 * n
	if a[0] == 1:
		print(0, end=' ')
	else:
		print(cur, end=' ')
	for i in range(n - 1):
		print(cur, end=' ')
	print()
	exit()
curr = alphabet[point] - 1
mina = 0
for i in range(n):
	if a[i] == mina:
		if curr > mina and (point == 0 or curr != alphabet[point - 1]):
			print(curr, end=' ')
			curr -= 1
		else:
			point += 1
			while point < len(alphabet) and alphabet[point] - 1 == alphabet[point - 1]:
				point += 1
			if point == len(alphabet):
				curr = 2 * n
			else:
				curr = alphabet[point] - 1
			print(curr, end=' ')
			curr -= 1
	else:
		print(mina, end=' ')
		mina = a[i]


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(str, input().split())
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [-1] * n
	d = [0] * 100009
	if a[0] != 0:
		b[0] = 0
		d[0] = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			d[a[i - 1]] = 1
	d[a[-1]] = 1
	c = 0
	for i in range(n):
		while d[c] == 1:
			c += 1
		if b[i] == -1:
			b[i] = c
			d[c] = 1
	print(*b)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _t in range(1):
	n = cin()
	a = li()
	mex = [-1] * 100005
	li = a[0]
	for i in range(1, n):
		if li != a[i]:
			mex[li] = a[i]
			li = a[i]
	mex[li] = -2
	li = 0
	for i in range(100005):
		if mex[i] == -1:
			li = i
			break
	x = li
	for i in range(li + 1, 100005):
		if mex[i] == -1:
			mex[li] = i
			li = i
	mex[li] = -2
	ans = [x]
	le = a[0]
	y = a[0]
	x = mex[x]
	if a[0] > 1:
		print(-1)
		exit(0)
	for i in range(1, n):
		if a[i] != le:
			le = a[i]
			ans.append(y)
			y = mex[y]
		else:
			ans.append(x)
			x = mex[x]
		if min(y, x) != a[i]:
			print(-1)
			exit(0)
	print(*ans)


n = int(input())
a = list(map(int, input().split(' ')))
temp = {}
counter = 0
ans = []
flag = False
for i in range(n):
	temp[a[i]] = True
if not counter in temp:
	ans.append(counter)
	counter += 1
else:
	while counter in temp:
		counter += 1
	ans.append(counter)
	counter += 1
if a[0] != 0 and a[0] != 1:
	print(-1)
	flag = True
for i in range(1, n):
	if a[i] > i + 1:
		print(-1)
		flag = True
	if a[i] != a[i - 1]:
		ans.append(a[i - 1])
	elif not counter in temp:
		ans.append(counter)
		counter += 1
	else:
		while counter in temp:
			counter += 1
		ans.append(counter)
		counter += 1
if not flag:
	print(*ans)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def check(a, b):
	n = len(a)
	bb = [False] * (n + 1)
	c = [0] * n
	j = 0
	z = 0
	for i in a:
		if i <= n:
			bb[i] = True
		while bb[j]:
			j += 1
		if b[z] != j:
			return False
		z += 1
	return True

def solve():
	n = mint()
	a = list(mints())
	b = [None] * n
	c = [False] * (n + 1)
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			if a[i - 1] <= n:
				c[a[i - 1]] = True
	if a[-1] <= n:
		c[a[-1]] = True
	if a[0] != 0:
		b[0] = 0
		c[0] = True
	j = 0
	for i in range(n):
		if b[i] is None:
			while c[j]:
				j += 1
			b[i] = j
			c[j] = True
	if check(b, a):
		print(' '.join(map(str, b)))
	else:
		print(-1)
solve()


n = int(input())
l = list(map(int, input().split()))
s = set(l)
x = 0
y = 1
for i in range(n):
	if l[i] != x:
		print(x, end=' ')
		x = l[i]
		if y == l[i]:
			y += 1
	else:
		while y in s:
			y += 1
		print(y, end=' ')
		y += 1


n = int(input())
a = list(map(int, input().split()))
b = [-1 for i in range(n)]
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
MEX = 0
j = 0
l = []
while j <= n - 1:
	if MEX < a[j]:
		l.append(MEX)
		MEX = MEX + 1
	elif MEX == a[j]:
		MEX = MEX + 1
		j = j + 1
	elif MEX > a[j]:
		j = j + 1
	else:
		l.append(MEX)
		MEX = MEX + 1
while len(l) < n:
	l.append(MEX)
	MEX = MEX + 1
j = 0
for i in range(n):
	if b[i] == -1:
		b[i] = l[j]
		j = j + 1
print(*b)


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
flag = True
used = set([a[0]])
for i in range(1, n):
	used.add(a[i])
	if i and a[i] < a[i - 1] or a[i] > i + 1:
		flag = False
if flag:
	h = []
	for i in range(int(1000000.0) + 1):
		if i not in used:
			h.append(i)
	b = []
	heapify(h)
	a.append(1)
	for i in range(n):
		b.append(heappop(h) if h else b[-1])
		if a[i] != a[i + 1]:
			heappush(h, a[i])
	print(*b)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
empty = []
if a[0] > 1:
	print(-1)
	exit()
elif a[0] == 1:
	b[0] = 0
else:
	empty.append(0)
for i in range(1, n):
	if a[i] > i + 1:
		print(-1)
		exit()
	if a[i] == a[i - 1]:
		empty.append(i)
	else:
		b[i] = a[i - 1]
		k = a[i] - a[i - 1] - 1
		j = len(empty) - 1
		while k > 0 and j >= 0:
			b[empty[j]] = a[i] - k
			empty.pop()
			j -= 1
			k -= 1
		if k > 0:
			print(-1)
			exit()
for i in range(len(b)):
	if b[i] == -1:
		b[i] = 1000000
print(*b)


n = int(input())
l = input().split()
li = [int(i) for i in l]
lo = [0 for i in range(n)]
set = 0
done = [0 for i in range(n)]
hashi = dict()
for i in li:
	hashi[i] = 1
for i in range(n):
	if li[i] != 0 and i == 0:
		lo[i] = 0
		done[i] = 1
		hashi[0] = 1
		continue
	if li[i] != li[i - 1] and i != 0:
		lo[i] = li[i - 1]
		done[i] = 1
curr = 0
for i in range(n):
	if done[i] != 0:
		continue
	while curr in hashi:
		curr += 1
	lo[i] = curr
	curr += 1
for i in lo:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
f = 0
c = [0] * (n + 1)
for i in range(n):
	if i == 0:
		c[a[i]] = 1
	else:
		if a[i] > i + 1:
			f = 1
			break
		c[a[i]] = 1
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
if f:
	print(-1)
else:
	x = 0
	for i in range(n):
		if b[i] == -1:
			while c[x % (n + 1)]:
				x = (x + 1) % (n + 1)
			c[x % (n + 1)] = 1
			b[i] = x
	print(*b)


def help():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	ans_arr = [-1] * n
	dicti = {}
	if arr[0] == 1:
		ans_arr[0] = 0
		dicti[0] = 1
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			ans_arr[i] = arr[i - 1]
			dicti[arr[i - 1]] = 1
	dicti[arr[-1]] = 1
	m = 0
	for i in range(n):
		while dicti.get(m, -1) == 1:
			m += 1
		if ans_arr[i] == -1:
			ans_arr[i] = m
			dicti[m] = 1
	print(*ans_arr)
for _ in range(1):
	help()


n = int(input())
a = list(map(int, input().split()))
b = []
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in range(n):
	c[a[i]] += 1
u = 0
v = c.index(0)
for i in range(n):
	if a[i] > u:
		b.append(u)
		d[u] = 1
		while u <= n and d[u] == 1:
			u += 1
		if u > v:
			v = u
			while v <= n and c[v] != 0:
				v += 1
	else:
		b.append(v)
		d[v] = 1
		c[v] = -1
		while v <= n and c[v] != 0:
			v += 1
print(*b)


n = int(input())
a = list(map(int, input().split()))
m = int(1000000.0)
b = [-1] * n
e = 0
v = [0] * m
for i in range(n):
	if a[i] != e:
		b[i] = e
		v[e] = 1
		e = a[i]
v[e] = 1
k = 0
for i in range(n):
	while v[k] == 1:
		k += 1
	if b[i] == -1:
		b[i] = k
		v[k] = 1
print(*b)


v = [0 for i in range(1000006)]
n = int(input())
a = [0]
a += list(map(int, input().split()))
flag = 1
for i in range(1, n + 1):
	if a[i] > i:
		flag = 0
		break
	v[a[i]] = 1
if flag == 0:
	print(-1)
else:
	b = [-1 for i in range(n + 1)]
	for i in range(2, n + 1):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			v[a[i - 1]] = 1
	nv = []
	for i in range(1000006):
		if v[i] == 0:
			nv.append(i)
	j = 0
	for i in range(1, n + 1):
		if b[i] == -1:
			b[i] = nv[j]
			j += 1
	for i in range(1, n + 1):
		print(b[i], end=' ')


import sys
input = sys.stdin.buffer.readline

def iinp() -> int:
	return int(input())

def linp() -> list:
	return [int(p) for p in input().split()]

def sinp():
	return input().decode('unicode-escape')[0:-2]
n = iinp()
a = linp()
s = set(a)
x = 0
y = 1
for i in a:
	if i == x:
		while y in s:
			y += 1
		print(y, end=' ')
		y += 1
	else:
		print(x, end=' ')
		x = i


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
if a[0] == 0 or a[0] == 1:
	maxi = -1
	if a[0] == 1:
		b[0] = 0
		maxi = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
	tofill = []
	i = 0
	while i < n:
		if b[i] == -1:
			tofill.append(i)
		elif b[i] != -1 and len(tofill) != 0:
			maxi = max(maxi, a[i - 1])
			for j in range(len(tofill)):
				if maxi != a[i] - 1:
					b[tofill[0]] = maxi + 1
					tofill.pop(0)
					maxi += 1
				else:
					break
			if maxi != a[i] - 1:
				print(-1)
				break
		i += 1
	if len(tofill) == 0 and b.count(-1) != 0:
		pass
	else:
		maxi = a[-1]
		for i in range(len(tofill)):
			b[tofill[i]] = maxi + 1
			maxi += 1
		print(*b)
else:
	print(-1)


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
v = True
for i in range(0, n):
	if a[i] > i + 1:
		v = False
	if i > 0:
		if a[i] < a[i - 1]:
			v = False
if v == False:
	print(-1)
else:
	c = []
	i = 0
	j = 0
	while i < n:
		if a[i] == j:
			i = i + 1
			j = j + 1
		elif j < a[i]:
			c.append(j)
			j = j + 1
		else:
			i = i + 1
	c = c + [a[n - 1] + 1 for i in range(0, n)]
	j = 0
	b = []
	for i in range(0, n):
		if i > 0:
			if a[i - 1] < a[i]:
				b.append(a[i - 1])
			else:
				b.append(c[j])
				j = j + 1
		else:
			b.append(c[j])
			j = j + 1
	print(' '.join(list(map(str, b))))


n = int(input())
a = list(map(int, input().split()))
f = 1
for i in range(n):
	if a[i] > i + 1:
		f = 0
		break
if f == 0:
	print(-1)
else:
	ans = [-1] * (n + 1)
	ind = [-1] * (n + 1)
	for i in range(n):
		ind[a[i]] = i
	done = [0] * (n + 1)
	for i in range(len(ind)):
		if ind[i] != -1:
			ans[ind[i] + 1] = i
			done[i] = 1
	i = 0
	j = 0
	while i < n:
		if ans[i] == -1:
			while j < n + 1:
				if done[j] == 0:
					ans[i] = j
					done[j] = 1
					break
				else:
					j += 1
		i += 1
	print(*ans[0:n])


import sys
n = int(input())
mas = list(map(int, input().split()))
s = set(mas)
now = 1
p = 0
for i in range(n):
	if mas[i] != p:
		print(p, end=' ')
		p = mas[i]
		if now == mas[i]:
			now += 1
	else:
		while now in s:
			now += 1
		print(now, end=' ')
		now += 1
print()


n = int(input())
a = list(map(int, input().split()))

def add(i):
	r = []
	if c[i]:
		while c[i]:
			r.append(i)
			i += 1
	return (i, r)
aa = set(a)
f = {i: 0 for i in aa}
for i in a:
	f[i] += 1
c = [False for i in range(n + 20)]
for i in a:
	c[i] = True
d = [i for i in aa][::-1]
rest = set()
i = 0
b = []
while d:
	if len(rest) > 1:
		print(-1)
		exit()
	t = 0
	x = d.pop()
	if rest:
		b.append(rest.pop())
		t += 1
	rest.add(x)
	while t < f[x]:
		(i, r) = add(i)
		b.append(i)
		i += 1
		rest.union(r)
		t += 1
print(*b)


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
l = [0] * (10 ** 5 + 1)
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		l[b[i]] = 1
l[a[n - 1]] = 1
d = []
for i in range(10 ** 5 + 1):
	if l[i] == 0:
		d.append(i)
k = 0
for i in range(n):
	if b[i] == -1:
		b[i] = d[k]
		k += 1
print(*b)


N = int(input())
A = list(map(int, input().split()))
rs = set(A)
mx = -1
p = -1
ans = []
for a in A:
	if p >= 0 and p != a:
		ans.append(p)
		if p == mx + 1:
			mx += 1
	else:
		mx += 1
		while mx in rs:
			mx += 1
		ans.append(mx)
	if mx + 1 < a:
		print(-1)
		exit()
	p = a
print(*ans)


n = int(input())
a = list(map(int, input().split()))
i = 0
temp = -1
b = [-1] * n
while i < n - 1:
	if a[i] != a[i + 1]:
		temp = a[i]
		b[i + 1] = temp
	i += 1
x = b.count(-1)
lis = [-1] * (n + 1)
for i in range(n):
	lis[a[i]] = 0
y = lis.count(-1)
arr = []
p = n + 1
for i in range(p):
	if lis[i] == -1:
		arr.append(i)
j = 0
for i in range(n):
	if b[i] == -1:
		b[i] = arr[j]
		j += 1
print(' '.join((str(x) for x in b)))


import math
import sys
from itertools import permutations
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
if arr[-1] == '\n':
	arr.pop()
ans = [-1] * n
tot = [0]
for i in range(n - 1):
	if arr[i] != arr[i + 1]:
		ans[i + 1] = arr[i]
		tot.append(i + 1)
if n == 1:
	pass
elif arr[-1] != arr[-2]:
	tot.append(n - 1)
cur = 0
done = 0
for i in range(n):
	if ans[i] == -1:
		while cur < len(tot) and done == arr[tot[cur]]:
			done += 1
			cur += 1
		if cur > len(tot):
			break
		ans[i] = done
		done += 1
print(*ans)


import os, io
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
failflag = 0
visited = set()
visited.add(a[0])
for i in range(1, n):
	if a[i - 1] != a[i]:
		b[i] = a[i - 1]
	if a[i] > i + 1:
		failflag = 1
		break
	visited.add(a[i])
if failflag == 1:
	print(-1)
	sys.exit()
counter = 0
visited2 = set()
for i in range(n):
	while counter in visited:
		counter += 1
	if b[i] == -1:
		b[i] = counter
		if not counter in visited:
			counter += 1
		elif counter in visited2:
			counter += 1
	else:
		visited2.add(b[i])
ans = []
for i in range(n):
	ans.append(str(b[i]))
print(' '.join(ans))


from sys import stdin
n = int(stdin.readline())
arr = list(map(int, stdin.readline().rstrip().split(' ')))
setarr = set(arr)
b = [-1] * n
x = 0
for i in range(n):
	if arr[i] > i + 1:
		print(-1)
		break
else:
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			b[i] = arr[i - 1]
	for i in range(n):
		if b[i] == -1:
			while x in setarr:
				x += 1
			b[i] = x
			x += 1
	print(*b)


n = int(input())
sp = list(range(n + 1))
prd = -1
b = []
a = []
for i in input().split():
	i = int(i)
	if i != prd:
		sp[i] = -1
	prd = i
	b += [i]
(pr, k) = (1, 0)
while pr:
	if sp[k] != -1:
		a += [sp[k]]
		k += 1
		pr = 0
	else:
		k += 1
for i in range(1, n):
	if b[i - 1] != b[i]:
		a += [b[i - 1]]
	else:
		pr = 1
		while pr:
			if sp[k] != -1:
				a += [sp[k]]
				k += 1
				pr = 0
			else:
				k += 1
print(*a)


n = int(input())
a = list(map(int, input().split()))
c = [0] * 1000001
for i in a:
	c[i] += 1
p = 0
q = []
sol = []
t = [0] * 1000001
for i in range(n + 1):
	if c[i] == 0:
		continue
	while c[i]:
		if q:
			c[i] -= 1
			sol.append(q[0])
			t[q[0]] += 1
			q.pop(0)
		else:
			while c[p] or t[p]:
				p += 1
			t[p] += 1
			sol.append(p)
			p += 1
			c[i] -= 1
	q.append(i)
print(*sol)


n = int(input())
aarr = list(map(int, input().split()))
tovisit = {t: 0 for t in range(aarr[-1] + 1)}
for k in aarr:
	tovisit[k] += 1
b = []
transit = []
i = 0
flag = True
for t in aarr:
	if t > i + 1:
		flag = False
		print(-1)
		break
	if transit:
		b.append(transit[0])
		del transit[0]
		tovisit[t] -= 1
		if tovisit[t] == 0 and t < i:
			transit.append(t)
		continue
	while i < aarr[-1] + 1 and tovisit[i]:
		i += 1
	b.append(i)
	i += 1
	tovisit[t] -= 1
	if tovisit[t] == 0 and t < i:
		transit.append(t)
if flag:
	print(*b)


n = int(input())
arr = list(map(int, input().split(' ')))
_max = max(arr)
count = dict()
seq = []
for i in range(n):
	if arr[i] not in count:
		count[arr[i]] = 1
	else:
		count[arr[i]] = count[arr[i]] + 1
if arr[0] > 1:
	print(-1)
else:
	error = 0
	if arr[0] == 0:
		next_zero = 1
		while next_zero in count and count[next_zero] > 0:
			next_zero += 1
		seq.append(next_zero)
		count[next_zero] = 1
		while next_zero in count and count[next_zero] > 0:
			next_zero += 1
	if arr[0] == 1:
		seq.append(0)
		count[0] = 1
		next_zero = 1
	for i in range(1, n):
		if arr[i] > i + 1:
			error = 1
			break
		else:
			count[arr[i - 1]] = count[arr[i - 1]] - 1
			if count[arr[i - 1]] == 0:
				seq.append(arr[i - 1])
				count[arr[i - 1]] = 1
			else:
				while next_zero in count and count[next_zero] > 0:
					next_zero += 1
				seq.append(next_zero)
				if next_zero <= _max:
					count[next_zero] = 1
				else:
					count[next_zero] = 0
	if error == 1:
		print(-1)
	else:
		print(*seq)


n = int(input())
l = list(map(int, input().split()))
d = {}
l1 = [0] * (10 ** 5 + 1)
cnt = 0
l3 = []
for i in l:
	if i not in d:
		d[i] = 0
for i in range(len(l1)):
	if i in d:
		continue
	else:
		l1[i] = 1
l2 = []
for i in range(len(l1)):
	if l1[i] != 0:
		l2.append(i)
	else:
		l3.append(i)
(j, z) = (0, 0)
l4 = []
for i in range(len(l)):
	if l[i] > l3[j]:
		l4.append(l3[j])
		j += 1
	else:
		l4.append(l2[z])
		z += 1
print(*l4)


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
for _ in range(t):
	n = iinput()
	a = rlinput()
	a = [0] + a
	b = [-1] * (n + 1)
	mex = [False] * (int(100000.0) + 3)
	for i in range(1, n + 1):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			mex[a[i]] = True
	mex[0] = True
	curr = 0
	for i in range(1, n + 1):
		while mex[curr]:
			curr += 1
		if b[i] == -1:
			b[i] = curr
			mex[curr] = True
	print(*b[1:])


n = int(input())
arr = list(map(int, input().split()))
flag = 0
vis = [0] * (10 ** 6 + 1)
for i in range(n):
	if arr[i] > i + 1:
		flag = 1
	vis[arr[i]] = 1
if flag == 1:
	print(-1)
	quit()
b = [-1] * n
for i in range(1, n):
	if arr[i - 1] != arr[i]:
		b[i] = arr[i - 1]
not_vis = []
for i in range(10 ** 6 + 1):
	if vis[i] == 0:
		not_vis.append(i)
j = 0
for i in range(n):
	if b[i] == -1:
		b[i] = not_vis[j]
		j += 1
print(*b)


from collections import defaultdict
from collections import Counter
import sys
input = sys.stdin.readline

def solve(n, a):
	m = max(a)
	sa = set(a)
	fill = [i for i in range(m, -1, -1) if i not in sa]
	ans = []
	a0 = 0
	for aa in a:
		if aa == a0:
			if fill:
				ans.append(fill.pop())
			else:
				ans.append(m + 1)
		if aa > a0:
			if fill and fill[-1] == a0:
				fill.pop()
			if fill and fill[-1] < aa:
				print(-1)
				return 0
			else:
				ans.append(a0)
				a0 = aa
	print(' '.join(map(str, ans)))

def main():
	n = int(input())
	a = list(map(int, input().split()))
	solve(n, a)
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
ch = 1
mx = 0
for i in range(n):
	if a[i] > i + 1:
		ch = 0
		break
	mx = max(mx, a[i])
if ch == 0:
	print(-1)
else:
	b = [-1] * n
	lost = list()
	if a[0] != 0:
		lost.append(0)
	j = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			if a[i - 1] == 0:
				j = i
			for j in range(a[i - 1] + 1, a[i]):
				lost.append(j)
	l = len(lost)
	for i in range(l, n):
		lost.append(a[-1] + 1)
	ct = 0
	for i in range(n):
		if b[i] == -1:
			b[i] = lost[ct]
			ct += 1
	print(*b)


def solve(A, n):
	free = []
	ans = [-1] * n
	lo = 0
	for (i, a) in enumerate(A):
		free.append([i, a])
		while lo < a:
			if not free:
				return None
			(j, y) = free.pop()
			if lo != y:
				ans[j] = lo
				lo += 1
			else:
				return
	while free:
		ans[free.pop()[0]] = 10 ** 6
	return ans
n = int(input())
A = list(map(int, input().split()))
ans = solve(A, n)
if ans is None:
	print(-1)
else:
	print(' '.join(map(str, ans)))


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	ar = inpt()
	d = {}
	for i in ar:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	b = []
	j = 0
	temp = {}
	for i in range(n):
		bl = False
		if i != 0 and ar[i] != ar[i - 1]:
			for k in temp.keys():
				if k not in d:
					bl = True
					b.append(k)
					temp.pop(k)
					d[ar[i]] -= 1
					if d[ar[i]] == 0:
						d.pop(ar[i])
					break
		if bl == False:
			while j in d:
				temp[j] = True
				j += 1
			b.append(j)
			d[ar[i]] -= 1
			if d[ar[i]] == 0:
				d.pop(ar[i])
			j += 1
	for i in b:
		print(i, end=' ')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve(n, a):
	fail = [-1]
	b = [None] * n
	s = {}
	t = []
	m = max(a) + 1
	for i in range(n):
		if a[i] > i + 1:
			return fail
		if i == 0:
			if a[i] == 1:
				b[i] = 0
				s[0] = 1
			continue
		if a[i] > a[i - 1]:
			b[i] = a[i - 1]
			s[b[i]] = 1
		if i == n - 1:
			s[a[i]] = 1
	s = [i for i in range(100001) if i not in s]
	for i in range(n):
		if b[i] is not None:
			for j in range(i - 1, -1, -1):
				if len(s) == 0 or b[j] is not None:
					break
				b[j] = s.pop(0)
	for i in range(n):
		if b[i] is None:
			b[i] = m
	return b
n = int(input().strip())
a = list(map(int, input().strip().split()))
print(' '.join(map(str, solve(n, a))))


n = int(input())
a = list(map(int, input().split()))
s1 = set(a)
s2 = set()
i = 0
c = 0
x = 0
lst = []
f = 1
while i < n:
	miss = a[i]
	if c == miss and x not in s1 and (x not in s2):
		lst.append(x)
		s2.add(x)
		x += 1
		i += 1
	elif c == miss and (x in s1 or x in s2):
		x += 1
	elif c != miss:
		lst.append(c)
		s2.add(c)
		i += 1
		while c in s2:
			c += 1
		if c != miss:
			f = 0
			break
if f == 1:
	print(*lst)
else:
	print(-1)


n = int(input())
l = list(map(int, input().split()))
from collections import Counter, defaultdict
if l[0] > 1:
	print(-1)
else:
	ans = True
	l2 = []
	i = 0
	d = defaultdict(int)
	l1 = [0] * n
	l3 = []
	l4 = []
	x = 0
	y = 0
	for i in range(n):
		if l[i] > i + 1:
			ans = False
		if d[l[i]] == 0:
			if i == 0 and l[i] == 0:
				l3.append(0)
			elif i == 0 and l[i] == 1:
				l1[i] = 0
			else:
				l1[i] = l[i - 1]
			l2.append(l[i])
			d[l[i]] += 1
		else:
			l3.append(i)
	for i in range(1, n + 2):
		if d[i] == 0:
			l4.append(i)
	j = 0
	for i in l3:
		if j != len(l4):
			l1[i] = l4[j]
			j += 1
		else:
			l1[i] = l4[-1]
	if ans == True:
		print(*l1)
	else:
		print(-1)


n = int(input())
lst = [int(i) for i in input().split()]
a = [-1] * n
visited = [-1] * 100001
flag = 0
for i in range(n):
	if lst[i] > i + 1:
		flag = 1
		break
	visited[lst[i]] = 1
not_v = list()
for i in range(100001):
	if visited[i] == -1:
		not_v.append(i)
for i in range(1, n):
	if lst[i] != lst[i - 1]:
		a[i] = lst[i - 1]
j = 0
for i in range(n):
	if a[i] == -1:
		a[i] = not_v[j]
		j += 1
print(*a)


import random

def fast(arr):
	result = [-1 for _ in arr]
	used = set()
	seen = set()
	prev = None
	for (i, elem) in enumerate(arr):
		if elem > i + 1:
			return None
		if i == 0:
			prev = elem
			seen.add(elem)
		elif elem not in seen:
			seen.add(elem)
			result[i] = prev
			used.add(prev)
			prev = elem
	ctr = 0
	for (i, elem) in enumerate(result):
		if elem == -1:
			while ctr in used or ctr == arr[i] or ctr in seen:
				ctr += 1
			result[i] = ctr
			used.add(ctr)
	return result

def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	result = fast(arr)
	if result is None:
		print(-1)
	else:
		print(' '.join((str(x) for x in result)))

def MEX(arr):
	ctr = 0
	while ctr in arr:
		ctr += 1
	return ctr

def check(arr, result):
	for i in range(len(arr)):
		print(i, arr[i], result[:i + 1], MEX(result[:i + 1]))
		if arr[i] != MEX(result[:i + 1]):
			return False
	return True

def test():
	arr = [0]
	result = fast(arr)
	print(result)
	print(check(arr, result))

def randomTest():
	t = 100
	for i in range(1, t + 1):
		n = random.randint(1, 10 ** 5)
		arr = sorted([random.randint(1, n) for _ in range(n)])
		print(i)
		result = fast(arr)
		if result is None:
			continue
main()


n = int(input())
nums = [int(x) for x in input().split()]
stack = []
ans = [-1] * n
for i in range(n - 1, 0, -1):
	if nums[i] > i + 1:
		print(-1)
		break
	if nums[i] == nums[i - 1]:
		if len(stack) > 0:
			ans[i] = stack.pop()
		else:
			ans[i] = 1000000
	else:
		ans[i] = nums[i - 1]
		delta = nums[i] - nums[i - 1]
		start = nums[i - 1] + 1
		for j in range(delta - 1):
			stack.append(start)
			start += 1
if nums[0] == 0:
	if len(stack) > 0:
		ans[0] = stack.pop()
	else:
		ans[0] = 1000000
elif nums[0] == 1:
	ans[0] = 0
for i in range(n):
	print(ans[i], end=' ')


n = int(input())
A = [int(x) for x in input().split()]
rs = set(A)
mx = -1
p = -1
ans = []
for a in A:
	if p >= 0 and p != a:
		ans.append(p)
		if p == mx + 1:
			mx += 1
	else:
		mx += 1
		while mx in rs:
			mx += 1
		ans.append(mx)
	if mx + 1 < a:
		print(-1)
		break
	p = a
print(*ans)


n = int(input())
a = list(map(int, input().split()))
ans = [-1] * n
for index in range(1, n):
	if a[index] != a[index - 1]:
		ans[index] = a[index - 1]
not_to_be_included = set(a)
init = 0
for index in range(n):
	if ans[index] == -1:
		while init in not_to_be_included:
			init += 1
		ans[index] = init
		init += 1
print(*ans)


import sys
input = sys.stdin.buffer.readline

def prog():
	n = int(input())
	array = list(map(int, input().split()))
	output = [-1] * n
	to_place = []
	prev = -1
	for i in range(n):
		curr = array[i]
		if curr != prev:
			output[i] = prev
			to_place.extend(list(range(prev + 1, curr))[::-1])
			prev = curr
	idx = 0
	for i in range(n):
		if output[i] == -1:
			if idx >= len(to_place):
				output[i] = 10 ** 6
			else:
				output[i] = to_place[idx]
				idx += 1
	sys.stdout.write(' '.join(map(str, output)) + '\n')
prog()


n = int(input())
ans = [-1] * n
se = set()
lis = list(map(int, input().split()))
length = len(lis)
for i in range(length - 1, 0, -1):
	if lis[i - 1] != lis[i]:
		ans[i] = lis[i - 1]
		se.add(lis[i - 1])
if lis[0] > 1:
	print(-1)
	exit()
i = 0
se.add(lis[-1])
j = 0
while True:
	if j == length:
		break
	if i in se:
		i += 1
		continue
	if ans[j] != -1:
		j += 1
		continue
	ans[j] = i
	j += 1
	i += 1
for i in ans:
	print(i, end=' ')


def main():
	n = int(input())
	mex = [int(x) for x in input().split()]
	arr = [n + 1] * n
	prev_mex = 0
	slots = []
	for i in range(n):
		if mex[i] > prev_mex:
			arr[i] = prev_mex
			nums_to_add = range(prev_mex + 1, mex[i])
			for num in nums_to_add:
				if len(slots) == 0:
					print(-1)
					return
				slot = slots.pop()
				arr[slot] = num
		else:
			slots.append(i)
		prev_mex = mex[i]
	print(' '.join((str(x) for x in arr)))
main()


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
if is_it_local():

	def debug(*args):
		st = ''
		for arg in args:
			st += f'{arg} '
		print(st)
else:

	def debug(*args):
		pass
import heapq

def main():
	n = input1()
	ar = input_array()
	mp = {}
	flg = 1
	last = 0
	for i in range(n - 1, -1, -1):
		if ar[i] not in mp:
			mp[ar[i]] = 0
		mp[ar[i]] += 1
		last = max(last, ar[i])
		if ar[i] > i + 1:
			flg = 0
	if flg == 0:
		print(-1)
		exit()
	ll = []
	heapq.heapify(ll)
	for i in range(0, last):
		if mp.get(i, 0) == 0:
			heapq.heappush(ll, i)
	res = []
	for v in ar:
		now = -1
		if len(ll) > 0:
			now = heapq.heappop(ll)
		else:
			now = last + 1
		res.append(now)
		mp[v] -= 1
		if mp[v] == 0:
			heapq.heappush(ll, v)
	print(' '.join((str(x) for x in res)))
	pass
main()


from sys import stdin, stdout
from sys import maxsize

def solve():
	pass
test = 1
for t in range(0, test):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = set(a)
	avail = []
	for i in range(10 * n):
		if not i in c:
			avail.append(i)
	b = []
	temp = a[0]
	j = 0
	m = a[0]
	for i in range(n):
		if temp != a[i]:
			if m + 1 < a[i] and temp < m:
				break
			if temp == m + 1 and a[i] > temp + 1:
				break
			b.append(temp)
			m = max(m, temp)
			(temp, z) = (a[i], i)
		else:
			z = avail[j]
			b.append(z)
			m = z
			j += 1
	if len(b) == n:
		for el in b:
			print(el, end=' ')
	else:
		print(-1)


arr_len = int(input())
arr = list(map(int, input().split()))
res = [-1]
for i in range(arr_len - 1):
	if arr[i] != arr[i + 1]:
		res.append(arr[i])
	else:
		res.append(-1)
low = 0
arr_set = set(arr)
for i in range(arr_len):
	if res[i] == -1:
		while low in arr_set:
			low += 1
		res[i] = low
		low += 1
for x in res:
	print(x, end=' ')
print()


import sys
input = sys.stdin.readline
import heapq as hp
N = int(input())
A = list(map(int, input().split()))
dic = {}
canuse = [True] * (N + 2)
for (i, a) in enumerate(A):
	dic[a] = i
	canuse[a] = False
q = []
for i in range(N + 1):
	if canuse[i]:
		hp.heappush(q, i)
ans = []
for (i, a) in enumerate(A):
	b = hp.heappop(q)
	ans.append(str(b))
	if dic[a] == i:
		hp.heappush(q, a)
print(' '.join(ans))


def solve(n, a):
	b = [-1] * n
	mex = 0
	s = []
	flag = 0
	for i in range(n):
		s.append(i)
		if a[i] + len(s) < mex:
			flag = 1
			print(-1)
			return
		while a[i] > mex:
			ind = s.pop()
			b[ind] = mex
			mex += 1
	random = 199967
	for i in range(n):
		if b[i] == -1:
			b[i] = random
			random += 1
	print(' '.join(map(str, b)))
n = int(input())
a = list(map(int, input().split()))
solve(n, a)


def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))
from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
INF = 10 ** 17
MOD = 1000000007
from fractions import *

def inverse(f):
	return 1 / f

def make_next(n, nums):
	imos = [0 for i in range(n)]
	for (i, num) in enumerate(nums):
		if num > i:
			imos[0] += 1
		else:
			imos[i - num] += 1
		if i + num + 1 < n:
			imos[i + num + 1] -= 1
	nx = []
	tmp = 0
	for im in imos:
		tmp += im
		nx.append(tmp)
	return nx

def mantan_check(n, nums):
	if sum(nums) == n ** 2:
		return True
	else:
		return False

def knapsack(tree, vx, l):
	dp = [0 for i in range(l + 1)]
	while True:
		dpcp = copy.copy(dp)
		(v, w) = tree[vx - 1]
		for (i, d) in enumerate(dp):
			if w + i < l + 1:
				if dpcp[w + i] < v + d:
					dpcp[w + i] = v + d
		dp = copy.copy(dpcp)
		vx //= 2
		dp = dpcp
		if vx == 0:
			break
	return max(dp)

def solve():
	n = getN()
	nums = getList()
	ans = [-1 for i in range(n)]
	prev = 0
	used = [0 for i in range(n + 10)]
	for (i, num) in enumerate(nums):
		if num != prev:
			ans[i] = prev
			used[prev] = 1
			prev = num
	used[nums[-1]] = 1
	used_idx = 0
	for i in range(n):
		if ans[i] == -1:
			while True:
				if used[used_idx] == 0:
					ans[i] = used_idx
					used_idx += 1
					break
				used_idx += 1
	print(*ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
solve()


from collections import deque
n = int(input())
bb = ''
c = [0 for j in range(n + 1)]
a = input().split(' ')
for j in range(n):
	a[j] = int(a[j])
	c[a[j]] = 1
b = [0 for j in range(n)]
k = 0
for j in range(n):
	if j == 0 or a[j] == a[j - 1]:
		while c[k] != 0:
			k += 1
		b[j] = k
		k += 1
	else:
		b[j] = a[j - 1]
for j in range(len(b)):
	bb += str(b[j]) + ' '
print(bb)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
arr = lmp()
chk = l1d(n + 1, True)
ansl = l1d(n, -1)
for i in range(n - 1):
	if arr[i + 1] != arr[i]:
		ansl[i + 1] = arr[i]
		chk[arr[i]] = False
chk[arr[-1]] = False
j = 0
for i in range(n):
	if ansl[i] == -1:
		while not chk[j]:
			j += 1
		ansl[i] = j
		chk[j] = False
print(*ansl)


maxn = 10 ** 6 + 5
vis = [False for i in range(maxn)]
n = int(input())
arr = list(map(int, input().split()))
for i in arr:
	vis[i] = True
ans = []
cnt = 0
for i in range(n):
	if i != 0:
		if arr[i] == arr[i - 1]:
			while vis[cnt]:
				cnt += 1
			vis[cnt] = True
			ans.append(cnt)
		else:
			ans.append(arr[i - 1])
	else:
		while vis[cnt]:
			cnt += 1
		ans.append(cnt)
		vis[cnt] = True
print(*ans)


import sys
import collections as cc
import bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ans = [-1] * n
temp = []
visi = [0] * (n + 1)
visi[l[-1]] = 1
for i in range(n - 1, 0, -1):
	if l[i] != l[i - 1]:
		ans[i] = l[i - 1]
		visi[l[i - 1]] = 1
j = 0
for i in range(n):
	if ans[i] == -1:
		while visi[j] == 1:
			j += 1
		ans[i] = j
		j += 1
print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
a = [0] + [int(item) for item in input().split()]
ans = [-1] * n
used = set()
for (i, (a1, a2)) in enumerate(zip(a, a[1:])):
	if a1 < a2:
		ans[i] = a1
		used.add(a1)
val = a[-1] - 1
max_val = max(a) + 1
to_use = []
for i in range(n - 1, -1, -1):
	if ans[i] != -1:
		continue
	while val in used:
		val -= 1
	if val >= 0:
		to_use.append(val)
		used.add(val)
to_use.sort()
itr = 0
for (i, item) in enumerate(ans):
	if item == -1:
		if itr < len(to_use):
			ans[i] = to_use[itr]
			itr += 1
		else:
			ans[i] = max_val
while val in used:
	val -= 1
print(' '.join([str(item) for item in ans]))


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
PI = 10 ** 6
for _ in range(1):
	n = nmbr()
	a = lst()
	f = 1
	ans = [-1] * n
	new = [0]
	pos = 0
	if a[0] == 1:
		ans[0] = 0
		pos = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			new += [i]
	for (p1, p2) in zip(new, new[1:]):
		ans[p2] = a[p1]
		for v in range(a[p1] + 1, a[p2]):
			while pos < n and ans[pos] != -1:
				pos += 1
			if pos >= n:
				f = 0
				break
			ans[pos] = v
			pos += 1
	for i in range(n):
		if ans[i] == -1:
			ans[i] = PI
	print(*(ans if f else -1))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
visit = [0] * 1000001
visit[a[0]] = 1
for j in range(1, n):
	if a[j] != a[j - 1]:
		b[j] = a[j - 1]
	visit[a[j]] = 1
start = 0
for j in range(n):
	if b[j] == -1:
		while visit[start] == 1:
			start += 1
		b[j] = start
		visit[start] = 1
		start += 1
		if start > 1000000:
			break
if b.count(-1) != 0:
	print(-1)
else:
	print(*b)


from sys import *
from heapq import *
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = list(range(1, n + 1))
chk = [0] * (n + 1)
flag = 0
q = []
for x in range(n):
	if a[x] > b[x]:
		flag = -1
	chk[a[x]] += 1
if flag == -1:
	print(-1)
	exit()
for x in range(n + 1):
	if chk[x] == 0:
		heappush(q, x)
t = heappop(q)
print(t, end=' ')
for x in range(1, n):
	if a[x - 1] != a[x]:
		print(a[x - 1], end=' ')
	else:
		t = heappop(q)
		print(t, end=' ')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
for _ in range(t):
	n = L()[0]
	l = L()
	b = [-1] * n
	vis = [0] * (n + 1)
	k = 0
	vis[l[-1]] = 1
	for i in range(n - 1, 0, -1):
		if l[i] != l[i - 1]:
			b[i] = l[i - 1]
			vis[l[i - 1]] = 1
	for i in range(n):
		if b[i] == -1:
			while vis[k] == 1:
				k += 1
			b[i] = k
			k += 1
	print(*b)


def solve(n, a):
	sol = [-1] * n
	mx = a[-1] + 1
	if a[0] == 1:
		sol[0] = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			sol[i] = a[i - 1]
	j = n - 1
	while sol[j] == -1:
		sol[j] = mx
		j -= 1
	if j > -1:
		used = [False] * a[j]
		for i in range(n):
			if sol[i] != -1 and sol[i] < len(used):
				used[sol[i]] = True
		i = len(used) - 1
		while j >= 0:
			if sol[j] != -1:
				used[sol[j]] = True
			else:
				while i >= 0 and used[i]:
					i -= 1
				if i >= 0 and i > a[j]:
					sol[j] = i
					used[i] = True
				else:
					sol[j] = mx
			j -= 1
	return sol
n = int(input())
a = list(map(int, input().split()))
s = solve(n, a)
print(' '.join(map(str, s)) if s else -1)


n = int(input())
a = list(map(int, input().split()))
b = set(a)
(k, t) = (0, 0)
not_in_set = []
for j in range(1, n + 1):
	if j not in b:
		not_in_set.append(j)
for i in range(n):
	if a[i] > i + 1:
		print(-1)
		break
	elif a[i] != k:
		print(k, end=' ')
		k = a[i]
	else:
		print(not_in_set[t], end=' ')
		t += 1


n = int(input())
list1 = list(map(int, input().strip().split()))
if list1[0] >= 2:
	print(-1)
else:
	free = []
	curr = 0
	b = 1
	ans = []
	for i in range(n):
		ans.append(-1)
	if list1[0] == 0:
		free.append(0)
	elif list1[0] == 1:
		ans[0] = 0
	for i in range(1, n):
		if list1[i] == list1[i - 1]:
			free.append(i)
		else:
			ans[i] = list1[i - 1]
			temp1 = len(free) - curr
			temp2 = list1[i] - list1[i - 1] - 1
			if temp2 > temp2:
				b = 0
				break
			for i in range(list1[i - 1] + 1, list1[i]):
				ans[free[curr]] = i
				curr += 1
	if b == 0:
		print(-1)
	else:
		maximum = list1[n - 1] + 1
		for i in range(curr, len(free)):
			ans[free[i]] = maximum
		for val in ans:
			print(val, end=' ')
		print()


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
q = [-1] * n
for i in range(1, n):
	if a[i] != a[i - 1]:
		q[i] = a[i - 1]
w = []
j = 0
for i in a:
	while j < n + 1 and j < i:
		w.append(j)
		j += 1
	if j == i:
		j += 1
w += [i for i in range(a[-1] + 1, 2 * n)]
k = 0
for i in range(n):
	if q[i] == -1:
		q[i] = w[k]
		k += 1
print(*q)


import bisect
n = int(input())
a = list(map(int, input().split()))
s = set()
b = [0] * n
m = 0
s = set()
for i in range(n - 1, -1, -1):
	if i == 0:
		if a[i] == 1:
			b[i] = 0
		elif len(s) > 0:
			b[i] = s.pop()
		else:
			b[i] = n + 1
	elif a[i] != a[i - 1]:
		b[i] = a[i - 1]
		for x in range(a[i - 1] + 1, a[i]):
			s.add(x)
	elif len(s) > 0:
		b[i] = s.pop()
	else:
		b[i] = n + 1
print(*b)


n = int(input())
a = list(map(int, input().split()))
g = []
c = a[0]
for u in range(c):
	g.append(u)
for i in range(1, n):
	if a[i] == a[i - 1]:
		pass
	else:
		for u in range(a[i - 1] + 1, a[i]):
			g.append(u)
if len(g) == 0:
	g.append(a[-1] + 1)
g += [g[0]] * n
b = [g[0]]
res = True
j = 1
for i in range(1, n):
	if a[i] > a[i - 1]:
		b.append(a[i - 1])
	else:
		b.append(g[j])
		j += 1
for i in range(n):
	print(b[i], end=' ')
print()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		if any((i < c for (i, c) in enumerate(a, 1))):
			rr.append(-1)
		else:
			a.append(0)
			s = set(a)
			k = 0
			r = []
			for (i, c) in enumerate(a[:-1]):
				if c != a[i - 1]:
					r.append(a[i - 1])
				else:
					while k in s:
						k += 1
					r.append(k)
					k += 1
			rr.append(JA(r, ' '))
	return JA(rr, '\n')
print(main())


def main():
	n = int(input())
	a = list(map(int, input().split()))
	ans = [n + 1] * n
	pred = 0
	slots = []
	for (i, el) in enumerate(a):
		if el > pred:
			nums = list(range(pred + 1, el))
			for j in nums:
				if not bool(slots):
					print(-1)
					return
				ans[slots.pop(0)] = j
			ans[i] = pred
		else:
			slots.append(i)
		pred = el
	print(*ans)
main()


from collections import defaultdict
n = int(input())
arr = [int(i) for i in input().split()]
b = [-1] * n
avail = defaultdict(int)
for i in range(1, n):
	if arr[i] != arr[i - 1]:
		b[i] = arr[i - 1]
		avail[b[i]] = 1
for i in range(n):
	avail[arr[i]] = 1
start = 0
for i in range(n):
	if b[i] == -1:
		while avail[start] == 1:
			start += 1
		b[i] = start
		avail[start] = 1
print(*b)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	if A[i] > i + 1:
		print(-1)
		sys.exit()
from collections import Counter
C = Counter(A)
ANS = []
now = 0
while now in C:
	now += 1
for i in range(n):
	for x in sorted([now, A[i - 1]]):
		if x in C:
			continue
		ANS.append(x)
		break
	C[x] += 1 << 31
	C[A[i]] -= 1
	if C[A[i]] == 0:
		del C[A[i]]
	while now in C:
		now += 1
print(*ANS)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	n = N()
	a = RLL()
	if any((a[i] > i + 1 for i in range(n))):
		print(-1)
	else:
		b = [0] * n
		ma = 10 ** 6
		q = deque()
		for i in range(n - 1, 0, -1):
			if a[i] > a[i - 1]:
				b[i] = a[i - 1]
				for j in range(a[i] - 1, a[i - 1], -1):
					q.append(j)
			elif q:
				b[i] = q.popleft()
			else:
				b[i] = ma
		if a[0] == 0:
			if q:
				b[0] = q.popleft()
			else:
				b[0] = ma
		print(*b)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	mx = 10 ** 6
	use = [False] * mx
	for (i, a) in enumerate(aa[1:], 1):
		if a > i:
			return [-1]
		use[a] = True
	bb = []
	j = 0
	for i in range(1, n + 1):
		if aa[i] == aa[i - 1]:
			while use[j]:
				j += 1
			use[j] = True
			bb.append(j)
		else:
			bb.append(aa[i - 1])
			use[aa[i - 1]] = True
	return bb
n = II()
aa = [0] + LI()
print(*main())


import heapq
import collections
n = int(input())
a = list(map(int, input().split()))
ctr = collections.Counter(a)
Q = [i for i in range(10 ** 6 + 1) if ctr.get(i) == None]
heapq.heapify(Q)
b = []
ctr = sorted(ctr.items())
for i in range(n):
	b.append(heapq.heappop(Q))
	(k, v) = ctr[0]
	if a[i] == k:
		v -= 1
		if v == 0:
			heapq.heappush(Q, k)
			ctr.pop(0)
		else:
			ctr[0] = (k, v)
	else:
		print(-1)
		break
else:
	print(' '.join(map(str, b)))


from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().strip().split(' ')))
p = True
for i in range(len(arr)):
	if arr[i] > i + 1:
		p = False
if not p:
	stdout.write('-1\n')
else:
	arr += [arr[-1] + 1]
	av = [1 for i in range(len(arr) + 10)]
	tarr = [-1 for i in range(len(arr))]
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			tarr[i] = arr[i - 1]
			av[arr[i - 1]] = 0
	ctr = 0
	for i in range(len(tarr)):
		if tarr[i] == -1:
			while av[ctr] == 0:
				ctr += 1
			tarr[i] = ctr
			ctr += 1
	stdout.write(' '.join(list(map(str, tarr[:-1]))) + '\n')


n = int(input())
a = list(map(int, input().split()))
l = []
r = []
s1 = set(a)
s2 = set([int(x) for x in range(n + 2)])
s3 = s2.difference(s1)
r = list(s3)
r.sort()
l.append(r[0])
r.remove(r[0])
for i in range(1, n):
	if a[i - 1] != a[i]:
		l.append(a[i - 1])
	else:
		l.append(r[0])
		r.remove(r[0])
print(*l)


n = int(input())
l = [int(x) for x in input().split()]
if l[0] > 1 or l[-1] > n:
	print(-1)
else:
	flag = 0
	dup = 0
	for i in range(n):
		if l[i] - i > 1:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		s1 = set(l)
		s2 = set([int(x) for x in range(0, n + 2)])
		s3 = s2.difference(s1)
		l1 = list(s3)
		l1.sort()
		ans = []
		if l[0] == 0:
			ans.append(l1.pop(0))
		else:
			l1.pop(0)
			ans.append(0)
		prev = l[0]
		for i in range(1, n):
			if l[i] == prev:
				ans.append(l1.pop(0))
			else:
				ans.append(prev)
				prev = l[i]
		print(*ans)


from heapq import *
for t in range(1):
	n = int(input().strip())
	s = list(map(int, input().strip().split()))[:n]
	res = 1
	for i in range(n - 1):
		if s[i] > i + 1 or s[i + 1] < s[i]:
			res = -1
	if res == -1:
		print(-1)
		break
	used = list(set(s)) + [n + 1] * n
	rest = list(set(range(2 * n)) - set(s))
	heapify(rest)
	heapify(used)
	startrest = 0
	res = []
	for j in s:
		if j <= used[0]:
			res.append(heappop(rest))
		else:
			res.append(heappop(used))
	print(*res)


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	svb = []
	svbc = 0
	ans = []
	pos = 0
	for i in range(n):
		if lst[i] == pos:
			svbc += 1
			ans.append(-1)
		elif lst[i] == pos + 1:
			ans.append(pos)
			pos += 1
		elif lst[i] > pos:
			ans.append(pos)
			for x in range(pos + 1, lst[i]):
				svb.append(x)
				svbc -= 1
			pos = lst[i]
			if svbc < 0:
				print(-1)
				return
	sh = -1
	for i in ans:
		if i != -1:
			print(i, end=' ')
		else:
			sh += 1
			if sh >= len(svb):
				print(1000000, end=' ')
			else:
				print(svb[sh], end=' ')
	print()
for t in range(1):
	solve()


import heapq
n = int(input())
a = [int(e) for e in input().split()]
used = set(a)
prior_queue = [i for i in range(n + 1) if i not in used]
heapq.heapify(prior_queue)
res_arr = []
flag = True
for i in range(len(a)):
	if a[i] >= (i + 1) * 2:
		flag = False
		break
	cur_elem = heapq.heappop(prior_queue)
	res_arr.append(cur_elem)
	if i + 1 < len(a) and a[i] < a[i + 1]:
		heapq.heappush(prior_queue, a[i])
if flag:
	for e in res_arr:
		print(e, end=' ')
else:
	print(-1, end='')
print()


from sys import stdin, stdout
from collections import deque
R = lambda : stdin.readline().strip()
RL = lambda : list(map(int, R().split(' ')))
output = lambda x: stdout.write(str(x))
n = int(R())
a = RL()
MX = 10 ** 5 + 5
ans = [0 if a[0] else -1]
rem = []
for i in range(1, n):
	if a[i] != a[i - 1]:
		rem.extend(list(range(a[i - 1] + 1, a[i])))
		ans.append(a[i - 1])
	else:
		ans.append(-1)
i = 0
for j in range(n):
	if len(rem) <= i and ans[j] == -1:
		ans[j] = MX
	elif ans[j] == -1:
		ans[j] = rem[i]
		i += 1
print(*ans)


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
n = int(input())
arr = list(map(int, input().split()))
temp = set(arr)
(a, b) = (0, 1)
ans = []
for i in range(n):
	if arr[i] != a:
		ans.append(a)
		if arr[i] == b:
			b += 1
	else:
		while b in temp:
			b += 1
		ans.append(b)
		b += 1
	a = arr[i]
print(*ans)


import sys
N = int(input())
a = [int(x) for x in input().split(' ')]
b = [0 for _ in range(N)]
st = []
for (i, x) in enumerate(a):
	dif = a[i] - a[i - 1] if i != 0 else a[i]
	if dif:
		if len(st) + 1 < dif:
			print(-1)
			sys.exit(0)
		else:
			b[i] = a[i - 1] if i != 0 else 0
			for j in range(dif - 1):
				b[st.pop()] = a[i - 1] + j + 1
	else:
		st.append(i)
for x in st:
	b[x] = a[-1] + 1
print(' '.join(map(str, b)))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = []
d = dict()
for i in range(n):
	if a[i] > i + 1:
		print(-1)
		exit()
for i in range(10 ** 6 + 20):
	d[i] = 0
for i in a:
	d[i] += 1
m = 10 ** 6
for i in range(n):
	if d[i] == 0:
		m = i
		break
back_m = m
for i in range(n):
	ans.append(m)
	d[m] += 1
	d[a[i]] -= 1
	if d[a[i]] == 0:
		m = a[i]
	else:
		m = back_m
		for j in range(m + 1, n):
			if d[j] == 0:
				m = j
				break
		back_m = m
print(*ans)


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	n = II()
	a = L()
	b = [-1] * n
	visited = [0] * (10 ** 6 + 1)
	visited[a[0]] = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
		visited[a[i]] = 1
	avail = []
	for i in range(10 ** 6 + 1):
		if visited[i] == 0:
			avail.append(i)
	k = 0
	for i in range(n):
		if b[i] == -1:
			b[i] = avail[k]
			k += 1
	print(*b)
solve()


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
n = I()
a = IL()
b = [-1 for x in a]
flag = 1
m = {}
for i in range(n):
	m[a[i]] = i + 1
for x in m:
	if m[x] < n:
		b[m[x]] = x
c = []
for i in range(2 * n + 1):
	if i in m:
		continue
	c.append(i)
c.sort()
x = 0
i = 0
j = 0
while i < n and j < 2 * n:
	if b[i] != -1:
		i += 1
		continue
	b[i] = c[j]
	j += 1
	i += 1
check = [-1 for i in a]
temp = 0
mp = {}
for i in range(n):
	mp[b[i]] = 1
	if b[i] == temp:
		while temp in mp and mp[temp] != 0:
			temp += 1
	check[i] = temp
for i in range(n):
	if check[i] != a[i]:
		flag = 0
		break
if flag == 1:
	for bb in b:
		print(bb, end=' ')
	print()
else:
	print(-1)


n = int(input().strip())
l = [int(a) for a in input().strip().split()]
ans = [0] * n
done = {}
index = {}
for i in range(n):
	done[l[i]] = 1
for i in range(1, n):
	if l[i] != l[i - 1]:
		ans[i] = l[i - 1]
		index[i] = 1
j = 0
for i in range(n):
	if i in index.keys():
		continue
	while j in done.keys():
		j += 1
	ans[i] = j
	j += 1
print(*ans)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 6 + 7
n = I()
a = list(R())
val = [1] * N
for i in a:
	val[i] = 0
stk = deque([i for i in range(a[-1]) if val[i]])
if not stk:
	stk = deque([a[-1] + 1])
ans = [stk.popleft()]
for i in range(1, n):
	if a[i] != a[i - 1]:
		ans += (a[i - 1],)
	elif stk:
		ans += (stk.popleft(),)
	else:
		ans += (ans[-1],)
print(*ans)


import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = [-1] * N
if a[0]:
	res[0] = 0
for i in range(N - 1):
	if a[i + 1] > a[i]:
		res[i + 1] = a[i]
s = sorted(set([x for x in range(N + 1)]) - set(a) - set(res), reverse=True)
for i in range(N):
	if res[i] == -1:
		res[i] = s.pop()
print(*res)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
b = [-1] * n
c = [False] * 1000000
c[a[0]] = True
for i in range(1, n):
	c[a[i]] = True
	if a[i] > a[i - 1]:
		b[i] = a[i - 1]
m = 0
for i in range(n):
	while c[m] == True:
		m += 1
	if b[i] == -1:
		b[i] = m
		c[m] = True
print(*b)


n = int(input())
a = list(map(int, input().split()))
p = 0
q = 1
t = set(a)
for i in a:
	if i == p:
		while q in t:
			q += 1
		print(q, end=' ')
		q += 1
	else:
		print(p, end=' ')
		p = i


from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().strip().split()))
if sorted(arr) != arr:
	print(-1)
else:
	flg = 0
	for i in range(n):
		if arr[i] - i > 1:
			flg = 1
			break
	if flg:
		print(-1)
	else:
		raj = dict()
		for i in range(n):
			raj[arr[i]] = 1
		x = -1
		ans = []
		for i in range(n):
			if i == 0:
				x = x + 1
				while x in raj:
					x += 1
				ans.append(x)
			elif arr[i - 1] != arr[i]:
				ans.append(arr[i - 1])
			else:
				x = x + 1
				while x in raj:
					x += 1
				ans.append(x)
		print(*ans)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	n = int(inp())
	a = lis()
	m = max(a)
	for i in range(0, n):
		if i >= a[i] - 1:
			continue
		else:
			print(-1)
			return
	b = [-1] * n
	nta = [False] * (m + 1)
	for i in range(1, n):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
	s = list(set(b))
	for i in s:
		nta[i] = True
	if a[0] == 0:
		curr = 1
	else:
		curr = 0
	toadd = []
	for i in range(0, m + 1):
		if nta[i] == False:
			toadd.append(i)
	for i in range(m + 1, 10 ** 6 + 1):
		toadd.append(i)
	j = 0
	for i in range(0, n):
		if b[i] == -1:
			b[i] = toadd[j]
			j += 1
	print(*b)
testcase(1)


n = int(input())
l = list(map(int, input().split()))
m = l[-1] + 1
d = {}
s = set(l)
for i in l:
	if i in d:
		d[i] = d[i] + 1
	else:
		d[i] = 1
o = []
for i in range(0, m):
	if i in s:
		pass
	else:
		o.append(i)
o = o[::-1]
p = []
for i in l:
	if len(o) == 0:
		p.append(m)
		m = m + 1
		d[i] = d[i] - 1
		if d[i] == 0:
			o.append(i)
	else:
		x = o.pop()
		p.append(x)
		d[i] = d[i] - 1
		if d[i] == 0:
			o.append(i)
print(*p)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	from heapq import heappop, heappush
	from collections import Counter
	n = int(input())
	a = list(map(int, input().split()))
	cnt = Counter(a)
	used = [0] * (2 * 10 ** 5)
	hq = [i for i in range(2 * 10 ** 5) if cnt[i] == 0]
	ans = []
	l = 0
	for (i, v) in enumerate(a):
		ans.append(heappop(hq))
		used[ans[-1]] = 1
		if not (all((used[j] for j in range(l, v))) and (not used[v])):
			print(-1)
			exit()
		l = v
		cnt[v] -= 1
		if cnt[v] == 0:
			heappush(hq, v)
	output(' '.join(map(str, ans)))
main()


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	b = [-1] * n
	l1 = []
	for i in range(1, n):
		if l[i - 1] != l[i]:
			l1.append([l[i - 1], l[i]])
	ch = 0
	l2 = []
	for i in range(len(l1)):
		for j in range(l1[i][0] + 1, l1[i][1]):
			l2.append(j)
	b = []
	j = 0
	if l[0] == 0:
		if j < len(l2):
			b.append(l2[j])
			j += 1
		else:
			b.append(n + 1)
	else:
		b.append(0)
	for i in range(1, n):
		if l[i] != l[i - 1]:
			b.append(l[i - 1])
		else:
			if j < len(l2):
				b.append(l2[j])
			else:
				b.append(n + 1)
			j += 1
	print(*b)


MAX = 10 ** 6 // 2
n = int(input())
A = list(map(int, input().split(' ')))
A.append(0)
B = [-1] * n
excluded = sorted(list(set(range(0, n + 1)) - set(A)), reverse=True)
for i in range(n):
	if A[i] != A[i - 1]:
		B[i] = A[i - 1]
	else:
		B[i] = MAX if len(excluded) == 0 else excluded.pop()
print(*B)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
for i in range(n):
	if arr[i] > i + 1:
		out(-1)
		exit()
c = C(arr)
answer = [-1] * n
m = 0
for i in range(n):
	if i > 0 and arr[i] != arr[i - 1]:
		answer[i] = arr[i - 1]
		m = max(arr[i], m)
	else:
		while c[m] > 0:
			m += 1
		answer[i] = m
		m += 1
	c[arr[i]] -= 1
out(*answer)


from collections import deque
N = int(input())
List = [int(x) for x in input().split()]
for i in range(N):
	if List[i] > i + 1:
		print(-1)
		exit()
Nahi = list(set(list(range(N + 1))).difference(set(List)))
Nahi.sort()
Ans = [Nahi[0]]
Added = deque()
Added.append(List[0])
index = 1
for i in range(1, N):
	if List[i] == List[i - 1]:
		if Added[-1] != List[i]:
			Added.append(List[i])
		Ans.append(Nahi[index])
		index += 1
	else:
		Ans.append(Added[0])
		Added.popleft()
		Added.append(List[i])
print(*Ans)


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
n = test
A = Neo()
C = Counter(A)
B = []
for i in range(n + 1):
	if i not in C:
		B.append(i)
B.sort()
B = deque(B)
Ans = []
for i in A:
	Ans.append(B.popleft())
	C[i] -= 1
	if C[i] == 0:
		B.appendleft(i)
print(*Ans)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *
from itertools import permutations
t = 1
while t > 0:
	t -= 1
	n = fi()
	a = li()
	d = [0 for i in range(n)]
	s = set([i for i in range(n + 1)])
	p = s - set(a)
	s = list(s)
	s.sort()
	ff = {}
	mex = 0
	for i in range(n):
		if a[i] > i + 1:
			print(-1)
			exit(0)
	j = 0
	m = len(p)
	p = list(p)
	for i in range(n):
		if i > 0 and a[i] != a[i - 1]:
			print(a[i - 1], end=' ')
		elif j >= m:
			print(0, end=' ')
		else:
			print(p[j], end=' ')
			j += 1


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
sa = set(a)
x = 0
for i in range(n):
	if b[i] == -1:
		while x in sa:
			x += 1
		b[i] = x
		x += 1
print(*b)


n = int(input())
a = list(map(int, input().split()))
b = [-1 for i in range(n)]
flag = 1
c = a[0]
r = {}
for i in range(1, n):
	if a[i] != c:
		b[i] = c
		r[c] = 1
		if i < c:
			flag = 0
			break
		c = a[i]
if n < c:
	flag = 0
avail = []
la = 0
for i in range(a[n - 1]):
	if r.get(i, 0) == 0:
		avail.append(i)
		la += 1
la += 1
avail.append(a[n - 1] + 1)
if flag == 0:
	print(-1)
else:
	j = 0
	for i in range(n):
		if b[i] == -1:
			b[i] = avail[j]
			if j < la - 1:
				j += 1
	for i in b:
		print(i, end=' ')


import sys
sys.setrecursionlimit(2 * 10 ** 5)
n = int(input())
l = [int(i) for i in input().split()]
check = [0] * (2 * 10 ** 5)
for i in l:
	check[i] = 1
ans = []
c = False
for i in range(n):
	if check[i] == 0:
		now = i
		c = True
		break
if not c:
	now = max(l) + 1
M = now
b = l[0]
for i in range(n):
	if b == l[i]:
		while now < n + 2 and check[now]:
			now += 1
		ans.append(now)
		check[now] = 1
		M = max(M, now)
	else:
		if now < b and check[b - 1]:
			if b - 1 == now:
				M = max(M, b)
				now = b
		ans.append(b)
		b = l[i]
	if M < l[i] - 1:
		print(-1)
		exit()
print(*ans)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
ans = 0
n = I()
a = LI()
ac = [a[0]]
m = [0] * (n + 2)
b = []
for i in range(n):
	m[a[n - 1 - i]] = n - 1 - i + 1
	if ac[-1] != a[i]:
		ac += [a[i]]
d = {i: j for (i, j) in zip(ac + [inf], ac[1:] + [inf] * 2)}
ac += [inf]
ac = ac[::-1]
s = set(ac)
q = []
for i in range(2 * n + 1)[::-1]:
	if i not in s:
		q += (i,)
mex = 0
j = 0
for i in range(n):
	if a[i] > ac[-1]:
		t = ac.pop()
	else:
		t = q.pop()
	b += (t,)
ans = b
print(*ans)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = [0] * n
count = 0
idxs = []
if a[0] == 0:
	idxs.append(0)
else:
	b[0] = 0
ok = True
for i in range(1, n):
	if a[i] == a[i - 1]:
		idxs.append(i)
	else:
		b[i] = a[i - 1]
		k = 1
		while k < a[i] - a[i - 1]:
			if len(idxs) == 0:
				ok = False
				print(-1)
				break
			b[idxs.pop()] = a[i - 1] + k
			k += 1
		if not ok:
			break
max_v = a[-1] * 2 if a[-1] != 0 else 1
while len(idxs):
	b[idxs.pop()] = max_v
s = ''
for i in b:
	s += f'{i} '
print(s)


from sys import stdin
input = stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
b = [-1] * n
vis = [0] * (n + 1)
x = y = 0
if a[0]:
	b[0] = 0
	vis[0] = 1
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		vis[a[i - 1]] = 1
		while 1:
			while vis[y]:
				y += 1
			if y >= a[i]:
				break
			while b[x] != -1:
				x += 1
			b[x] = y
			vis[y] = 1
			x += 1
x = 100005
for i in range(n):
	if b[i] == -1:
		b[i] = x
		x += 1
print(*b)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	a = [0] * (10 ** 6 + 1)
	for i in range(n):
		if l[i] > i + 1:
			print(-1)
			return
		a[l[i]] = 1
	x = []
	for i in range(len(a)):
		if a[i] == 0:
			x.append(i)
	j = 1
	ans = [x[0]]
	for i in range(1, n):
		if l[i] == l[i - 1]:
			ans.append(x[j])
			if j != n - 1:
				j += 1
		else:
			ans.append(l[i - 1])
	print(*ans)
solution()


production = True
import sys, math

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$')
		print(*args)

def solve():
	n = input(11)
	a = input(1)
	if a != sorted(a):
		out(-1)
		return
	y = set(a)
	p = []
	for i in range(3 * 10 ** 6, -1, -1):
		if i not in y:
			p.append(i)
	k = []
	log(a)
	for (i, j) in enumerate(a):
		log(i, j)
		k.append(p.pop())
		if i < n - 1 and j < a[i + 1]:
			p.append(j)
	log(k)
	out(k, 1)
	return
solve()


n = int(input())
A = [int(i) for i in input().split()]
for i in range(n):
	if A[i] > i + 1:
		print(-1)
		break
else:
	ans = [-1] * n
	visited = [False] * (n + 1)
	for i in range(1, n):
		if A[i] != A[i - 1]:
			ans[i] = A[i - 1]
			visited[A[i - 1]] = True
	visited[A[-1]] = True
	pointer = 0
	for i in range(n):
		if ans[i] == -1:
			while visited[pointer]:
				pointer += 1
			visited[pointer] = True
			ans[i] = pointer
print(*ans)


def solve(nums):
	res = [None] * len(nums)
	used = set()
	if nums[0] == 1:
		res[0] = 0
		used.add(0)
	if nums[0] != 0 and nums[0] != 1:
		return -1
	for i in range(1, len(nums)):
		if nums[i] > i + 1:
			return -1
		if nums[i] != nums[i - 1]:
			res[i] = nums[i - 1]
		used.add(nums[i - 1])
	largest = nums[-1]
	i = 0
	for x in range(0, largest):
		while i < len(res) and res[i] != None:
			i += 1
		if x not in used:
			res[i] = x
			i += 1
	for i in range(len(res)):
		if res[i] == None:
			res[i] = largest + 1
	return ' '.join([str(x) for x in res])
input()
nums = list(map(int, input().split()))
print(solve(nums))


n = int(input())
a = list(map(int, input().split()))
se = set(range(n + 1)) - set(a)
li = list(se)
li.sort()
pre = 0
idx = 0
ans = []
for i in range(n):
	if a[i] > pre:
		ans.append(pre)
		if pre in se and idx < len(li) - 1:
			idx += 1
		pre = a[i]
	else:
		ans.append(li[idx])
		if idx < len(li) - 1:
			idx += 1
print(*ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arr = [int(x) for x in input().split()]
if arr[0] > 1:
	print(-1)
	sys.exit()
last = arr[-1]
required = []
used = set()
i = n - 1
MAX = int(1000000.0) - 1
ans = [0 for x in range(n)]
while i > 0:
	if arr[i] > i + 1:
		print(-1)
		sys.exit()
	if arr[i - 1] != arr[i]:
		ans[i] = arr[i - 1]
		for x in range(arr[i - 1] + 1, arr[i]):
			required.append(x)
	elif len(required):
		ans[i] = required.pop()
	else:
		ans[i] = MAX
	i -= 1
if arr[0] == 0:
	if len(required):
		ans[0] = required.pop()
	else:
		ans[0] = MAX
for item in ans:
	print(item, end=' ')


import sys
input = sys.stdin.readline
t = int(input())
n = set([i for i in range(t + 1)])
l = list(map(int, input().split()))
ss = set(l)
pp = list(n.difference(ss))
pp.sort()
for el in range(len(l)):
	if l[el] > el + 1:
		print(-1)
		exit()
b = [pp[0]]
c = 1
for el in range(1, len(l)):
	if l[el] > l[el - 1]:
		b.append(l[el - 1])
	else:
		b.append(pp[c])
		c += 1
print(*b)


n = int(input())
num = tuple(map(int, input().split()))
s = set(num)
ss = set()
prev = 0
m = 0
ans = [0] * n
for i in range(n):
	cur = num[i]
	if cur == prev:
		while m in s:
			m += 1
		ans[i] = m
		s.add(m)
		ss.add(m)
	else:
		ans[i] = prev
		s.add(prev)
		ss.add(prev)
		while prev in ss:
			prev += 1
		if prev != cur:
			print(-1)
			break
else:
	print(*ans)


from sys import stdin

def intJoin(arr):
	return ' '.join([str(i) for i in arr])

def answer(arr):
	arr = [arr[0] - 1] + arr
	a = []
	b = []
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			a.append(arr[i - 1])
			b.append(arr[i - 1])
		else:
			b.append(-1)
	if arr[-1] - a[-1] > 1:
		a.append(arr[-1])
	c = []
	for i in range(1, len(a)):
		if a[i] - a[i - 1] > 1:
			for j in range(a[i - 1] + 1, a[i]):
				c.append(j)
	c = list(reversed(c))
	for i in range(0, len(b)):
		if b[i] == -1:
			if len(c) == 0:
				b[i] = arr[-1] + 1
			else:
				b[i] = c.pop()
	return intJoin(b)
n = int(input())
arr = list(map(int, stdin.readline().split()))
print(answer(arr))


def main():
	n = int(input())
	ar = list(map(int, input().split()))
	if n == 1:
		print((1, 0)[ar[0] > 0])
		return
	res = [-1] * n
	s = set(ar)
	mx = -1
	for i in range(1, n):
		if ar[i] > ar[i - 1]:
			res[i] = ar[i - 1]
			mx = max(mx, res[i])
	j = 0
	for i in range(n):
		if res[i] == -1:
			while j in s:
				j += 1
			res[i] = j
			mx = max(mx, j)
			j += 1
	if ar[n - 1] - mx > 1:
		print(-1)
		return
	for x in res:
		print(x, end=' ')
	print()
main()


import heapq
n = int(input())
(*arr,) = map(int, input().split())
first = {}
last = {}
for i in range(n):
	last[arr[i]] = i
big_number = max(arr) + 1
b = [-1] * n
used = set()
for i in range(n):
	if i == 0 or arr[i] != arr[i - 1]:
		last_idx = last[arr[i]]
		if last_idx != n - 1:
			b[last_idx + 1] = arr[i]
			used.add(arr[i])
used.add(arr[-1])
max_val = max(arr) + 1
l = arr[-1] - 1
l = 0
for i in range(n):
	if b[i] == -1:
		while l in used:
			l += 1
		b[i] = l
		l += 1
print(*b)


from sys import stdin
import heapq
n = int(stdin.readline())
nums = [int(x) for x in stdin.readline().split()]
high = max(nums)
no = set(nums)
need = []
for x in range(high):
	if not x in no:
		need.append(x)
heapq.heapify(need)
out = []
for x in range(len(nums)):
	if need:
		out.append(heapq.heappop(need))
	else:
		out.append(high + 1)
	if x != n - 1:
		if nums[x + 1] != nums[x]:
			heapq.heappush(need, nums[x])
low = 0
things = [False for x in range(high + 5)]
valid = True
for (i, x) in enumerate(out):
	things[x] = True
	while things[low]:
		low += 1
	if low != nums[i]:
		valid = False
		break
if valid:
	print(' '.join([str(x) for x in out]))
else:
	print(-1)


n = int(input())
ans = []
a = list(map(int, input().split()))
oset = set((i for i in range(2 * n + 1)))
aset = set(a)
iset = oset - aset
ilist = sorted(list(iset), reverse=True)
for j in range(n):
	ans.append(ilist[-1])
	de = a.pop(0)
	if len(a) and a[0] != de:
		ilist.pop(-1)
		ilist.append(de)
	else:
		ilist.pop(-1)
for kk in ans:
	print(kk, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = [n + 1] * n
isCovered = [False] * a[n - 1]
lastIsNotCovered = 0
allCovered = False
for i in range(n - 1):
	if a[i] != a[i + 1]:
		b[i + 1] = a[i]
		isCovered[a[i]] = True
for i in range(lastIsNotCovered, a[n - 1]):
	if isCovered[i] == False:
		lastIsNotCovered = i
		break
	if i == a[n - 1] - 1:
		allCovered = True
		break
if a[n - 1] == 0:
	allCovered = True
for i in range(n):
	if allCovered:
		break
	if b[i] != n + 1:
		continue
	else:
		b[i] = lastIsNotCovered
		if lastIsNotCovered == a[n - 1] - 1:
			allCovered = True
			break
		isCovered[lastIsNotCovered] = True
		for j in range(lastIsNotCovered, a[n - 1]):
			if isCovered[j] == False:
				lastIsNotCovered = j
				break
			if j == a[n - 1] - 1:
				allCovered = True
				break
		if allCovered:
			break
if allCovered:
	output = [str(i) for i in b]
	print(' '.join(output))
else:
	print(-1)


from sys import stdin, stdout
import sys
from math import *
n = int(input())
ar = list(map(int, input().split()))
ans = []
for i in range(n):
	if ar[i] > i + 1:
		print(-1)
		exit()
ans = [-1] * n
d = {}
for i in range(1, n):
	if ar[i] != ar[i - 1]:
		d[ar[i - 1]] = 1
		ans[i] = ar[i - 1]
d[ar[-1]] = 1
x = 0
for i in range(n):
	if ans[i] == -1:
		while 1:
			if d.get(x) == None:
				ans[i] = x
				x += 1
				break
			x += 1
print(*ans)


n = int(input())
dp = list(map(int, input().split()))
l = []
u = []
for i in range(0, n + 1):
	l.append(0)
for i in range(0, n):
	l[dp[i]] = 1
for i in range(0, n + 1):
	if l[i] == 0:
		u.append(i)
j = 0
print(u[j], end=' ')
j += 1
for i in range(1, n):
	if dp[i - 1] != dp[i]:
		print(dp[i - 1], end=' ')
	else:
		print(u[j], end=' ')
		j += 1


a = int(input())
b = list(map(int, input().split()))
c = [0] * 1000001
d = [-1] * 1000001
for i in range(1, a):
	if b[i] != b[i - 1]:
		d[i] = b[i - 1]
		c[b[i - 1]] = 1
m = 0
c[b[a - 1]] = 1
for i in range(a):
	while c[m]:
		m += 1
	if d[i] == -1:
		d[i] = m
		c[m] = 1
	print(d[i], end=' ')


n = int(input())
s = list(map(int, input().split()))
stack = list()
for i in range(n, s[-1], -1):
	stack.append(i)
for i in range(len(s) - 1, 0, -1):
	if s[i] == s[i - 1]:
		continue
	else:
		for j in range(s[i] - 1, s[i - 1], -1):
			stack.append(j)
fin_list = list()
if s[0] == 1:
	stack.append(0)
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		curr_val = stack.pop(-1)
		fin_list.append(curr_val)
		stack.append(s[i])
	else:
		curr_val = stack.pop(-1)
		fin_list.append(curr_val)
curr_val = stack.pop(-1)
fin_list.append(curr_val)
print(*fin_list)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, input().split()))

def In():
	return map(int, input().split())

def I():
	return int(input())
P = 1000000007

def main():
	n = I()
	arr = L()
	val = set(arr)
	(p, q) = (0, 1)
	for i in range(n):
		if arr[i] == p:
			while q in val:
				q += 1
			print(q, end=' ')
			q += 1
		else:
			print(p, end=' ')
			p = arr[i]
main()


n = int(input())
a = list(map(int, input().split()))
l = [0] * (n + 2)
for elem in a:
	l[elem] = 1
not_present = []
for i in range(n + 2):
	if l[i] == 0:
		not_present.append(i)
j = 0
b = []
for i in range(n):
	if i == 0:
		b.append(not_present[j])
		j += 1
	elif a[i] != a[i - 1]:
		b.append(a[i - 1])
	else:
		b.append(not_present[j])
		j += 1
print(*b)


import sys, heapq
max_int = 1000000001
min_int = -max_int
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
d = {}
maxa = max(a)
to_add = set(range(0, maxa + 2))
for (num, one) in enumerate(a):
	if one - num >= 2:
		print(-1)
		exit()
	d[one] = num
	to_add.discard(one)
h = list(to_add)
del to_add
heapq.heapify(h)
out = []
last = -1
for (num, elem) in enumerate(a):
	if h:
		last = heapq.heappop(h)
	out.append(last)
	if num == d[elem]:
		heapq.heappush(h, elem)
print(' '.join(map(str, out)))


import sys
input = sys.stdin.readline
t = 1
for _ in range(t):
	maxi = 10 ** 6
	n = int(input())
	arr = list(map(int, input().split()))
	l = [-1] * n
	vacant = n
	left = max(arr)
	cur = arr[0]
	used = [-1] * (10 ** 6 + 1)
	allow = arr[-1] - 1
	for i in range(n):
		if arr[i] != cur:
			l[i] = cur
			used[cur] = 1
			cur = arr[i]
			vacant -= 1
			left -= 1
	if l[-1] == -1:
		l[-1] = 10 ** 6
		used[10 ** 6] = 1
		vacant -= 1
	for i in range(n - 2, -1, -1):
		while used[allow] == 1:
			allow -= 1
		while used[maxi] == 1:
			maxi -= 1
		if (arr[i] < allow or vacant <= left) and allow >= 0:
			if l[i] == -1:
				l[i] = allow
				used[allow] = 1
				allow -= 1
				left -= 1
				vacant -= 1
		elif arr[i] >= allow:
			if l[i] == -1:
				l[i] = maxi
				used[maxi] = 1
				maxi -= 1
				vacant -= 1
	if arr[0] == 1 and len(arr) == 1:
		print(0)
	elif left > 0:
		print(-1)
	else:
		print(*l)


n = int(input())
arr = [int(x) for x in input().split()]
end = arr[-1]
stack = []
setarr = set(arr)
for x in range(end):
	if x not in setarr:
		stack.append(x)
stack.reverse()
soln = []
for i in range(n):
	if len(stack) == 0:
		soln.append(end + 1)
	else:
		soln.append(stack.pop())
	if i < n - 1 and arr[i + 1] > arr[i]:
		stack.append(arr[i])
print(' '.join([str(x) for x in soln]))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
d = set(a)
done = {}
m = 0
while m in d:
	m += 1
b[0] = m
done[b[0]] = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		curr = m + 1
		while curr in d:
			curr += 1
		b[i] = curr
		done[b[i]] = 1
		m = max(m, b[i])
	else:
		if a[i - 1] not in done:
			b[i] = a[i - 1]
		else:
			curr = m + 1
			while curr in d:
				curr += 1
			b[i] = curr
		done[b[i]] = 1
		m = max(m, b[i])
print(*b)


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	seta = set(A)
	mex = 0
	ans = []
	ma = 0
	for (i, a) in enumerate(A):
		if a == mex:
			if len(ans) == 0:
				for j in range(1, N + 1):
					if j not in seta:
						ans.append(j)
						ma = max(ma, j)
						break
				else:
					print(-1)
					return
			else:
				for j in range(max(mex, ma) + 1, N + 1):
					if j not in seta:
						ans.append(j)
						ma = max(ma, j)
						break
				else:
					print(-1)
					return
		else:
			ans.append(mex)
			ma = max(ma, mex)
			mex = a
	print(*ans)
main()


n = int(input())
a = list(map(int, input().split()))
ans = [-1 for _ in range(n)]
mex = 0
ind = 0
for i in range(n):
	if mex < a[i]:
		for j in range(mex + 1, a[i]):
			while ind < i and ans[ind] != -1:
				ind += 1
			if ind == i:
				print(-1)
				exit()
			ans[ind] = j
		ans[i] = mex
		mex = a[i]
for i in range(len(ans)):
	if ans[i] == -1:
		print(1000000, end=' ')
	else:
		print(ans[i], end=' ')


n = int(input())
arr = list(map(int, input().strip().split()))[:n]
from collections import defaultdict
store = defaultdict(int)
ans = [-1] * n
for num in arr:
	store[num] = True
for i in range(1, n):
	if arr[i] > i + 1:
		print(-1)
		exit(0)
	elif i > 0 and arr[i] != arr[i - 1]:
		ans[i] = arr[i - 1]
		store[arr[i - 1]] = True
low = 0
for i in range(n):
	if ans[i] == -1:
		while store[low] == True:
			low += 1
		ans[i] = low
		store[low] = True
	print(ans[i], end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
l = [0] * 1000001
for i in a:
	l[i] = 1
(s, np, f, j, k) = ([], [], [], 0, 0)
for i in range(0, 1000001):
	if l[i] == 0:
		np.append(i)
w = len(np)
fg = 0
for i in range(0, n):
	if a[i] > i + 1:
		fg = 1
		break
if fg == 1:
	print(-1)
else:
	for i in range(0, n):
		b = len(s)
		if j < b and k < w:
			if s[j] < np[k] and s[j] != a[i]:
				f.append(s[j])
				j += 1
			else:
				f.append(np[k])
				k += 1
		elif k >= w and j < b:
			if s[j] == a[i]:
				fg = 1
				break
			else:
				f.append(s[j])
				j += 1
		elif k < w and j >= b:
			f.append(np[k])
			k += 1
		else:
			fg = 1
			break
		if b != 0:
			if s[b - 1] != a[i]:
				s.append(a[i])
		else:
			s.append(a[i])
if fg == 1:
	print(-1)
else:
	print(' '.join((str(a) for a in f)))


import os
import sys, math
from io import BytesIO, IOBase

def main():
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	for i in range(n):
		if i + 1 < l[i]:
			print(-1)
			return
		s.add(l[i])
	b = []
	v = 0
	chk = True
	for i in range(n):
		while v in s:
			v += 1
		if i > 0 and l[i] != l[i - 1]:
			b.append(l[i - 1])
		else:
			b.append(v)
			v += 1
	for c in b:
		print(c, end=' ')
	print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
left = []
i = 0
for x in range(a[n - 1] + 1):
	if a[i] > x:
		left.append(x)
	elif a[i] <= x:
		while i < n and a[i] <= x:
			i += 1
left.append(a[n - 1] + 1)
if a[0] != 0 and a[0] != 1:
	print('-1')
else:
	b = [left[0]]
	j = 1
	k = 1
	while j < n:
		if a[j] != a[j - 1]:
			b.append(a[j - 1])
			j += 1
		elif k < len(left):
			b.append(left[k])
			k += 1
			j += 1
		else:
			b.append(b[j - 1])
			j += 1
	for i in range(n):
		print(b[i], end=' ')


def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = 1
for _ in range(Testcase):
	n = inin()
	a = inar()
	i = 1
	s = set(a[:])
	d = [-1 for i in range(n)]
	while i < n:
		if a[i] != a[i - 1]:
			d[i] = a[i - 1]
		i += 1
	a = set([i for i in range(0, 100009)])
	a = a.difference(s)
	for i in range(n):
		if d[i] == -1:
			d[i] = a.pop()
	print(*d)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
n = oint()
a = list(rint())
ans = [-1] * n
used = set()
for i in range(1, n):
	if a[i - 1] == a[i]:
		continue
	ans[i] = a[i - 1]
	used.add(ans[i])
used.add(a[-1])
cur = 0
for i in range(n):
	if ans[i] != -1:
		continue
	for j in range(cur, 10 ** 9, 1):
		if j not in used:
			ans[i] = j
			cur = j + 1
			break
print(*ans)


import math
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if a[0] > 1:
	print(-1)
else:
	q = deque()
	for i in range(1, n):
		z = a[i] - a[i - 1]
		if z > 1:
			for j in range(1, z):
				q.append(a[i - 1] + j)
	ans = []
	k = 1
	if a[0] == 1:
		ans.append(0)
	elif q:
		ans.append(q.popleft())
	else:
		ans.append(100001)
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans.append(a[i - 1])
		elif q:
			ans.append(q.popleft())
		else:
			ans.append(100001)
	print(*ans)


n = int(input())
a = list(map(int, input().split()))

def mex(n, a):
	if a[0] > 1:
		print(-1)
		return
	unuse = list(range(2 * 10 ** 5 + 3, -1, -1))
	used = set(a)
	unused = [t for t in unuse if t not in used]
	ret = []
	i = 0
	while i < len(a):
		if i - 1 >= 0 and a[i] != a[i - 1]:
			ret.append(a[i - 1])
			if unused[-1] <= a[i]:
				print(-1)
				return
		else:
			ret.append(unused.pop())
		i += 1
	print(' '.join(map(str, ret)))
mex(n, a)


import os, io
from sys import stdout
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
l = list(map(int, input().split()))
result = [-1] * n
cant = [0] * (n * 2)
cant[l[-1]] = 1
for i in range(1, n):
	if l[i] != l[i - 1]:
		result[i] = l[i - 1]
		cant[result[i]] = 1
i = 0
for j in range(n):
	while cant[i]:
		i += 1
	if result[j] == -1:
		result[j] = i
		cant[i] = 1
print(' '.join([str(e) for e in result]))


import math
n = int(input())
array = list(map(int, input().split()))
dict_num = {}
ans = 0
for i in range(n):
	if array[i] > i + 1 or (i + 1 < n and array[i] > array[i + 1]):
		ans = -1
		break
	dict_num[array[i]] = 0
if ans == -1:
	print(-1)
else:
	stored = []
	not_stored = []
	for i in range(n, -1, -1):
		if i in dict_num:
			stored.append(i)
		else:
			not_stored.append(i)
	ans = []
	for i in range(n):
		if ans == []:
			ans.append(not_stored[-1])
			not_stored.pop()
		else:
			new = 0
			if dict_num[stored[-1]] == 1:
				new = stored[-1]
				stored.pop()
			else:
				new = not_stored.pop()
			ans.append(new)
		if i + 1 < n:
			if array[i] != array[i + 1]:
				dict_num[array[i]] = 1
	print(*ans)


n = int(input())
a = list(map(int, input().split()))
m = set(a)
u = [i for i in range(n + 1) if i not in m]
if a[0] not in [0, 1]:
	print(-1)
	exit()
b = [u.pop(0)]
for i in range(1, n):
	if a[i] != a[i - 1]:
		b.append(a[i - 1])
	else:
		b.append(u.pop(0))
print(*b)


import sys
input = sys.stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
inA = [0] * (n + 5)
for x in a:
	inA[x] += 1
keep = [0]
ma = 0
ans = []
for i in range(n):
	if keep and (not inA[keep[0]]):
		ans.append(keep.pop(0))
	else:
		ma += 1
		while inA[ma]:
			keep.append(ma)
			ma += 1
		ans.append(ma)
	if ma + 1 < a[i]:
		print(-1)
		exit()
	inA[a[i]] -= 1
print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	dic = defaultdict(int)
	res = [-1] * n
	if arr[0] == 1:
		res[0] = 0
	for i in range(n):
		dic[arr[i]] = max(dic[arr[i]], i)
	for i in dic:
		if dic[i] + 1 < n:
			res[dic[i] + 1] = i
	now = 1
	for i in range(n):
		if res[i] == -1:
			while now in dic:
				now += 1
			res[i] = now
			now += 1
	for i in range(n):
		if arr[i] > i + 1:
			print(-1)
			break
	else:
		print(*res)
main()


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
mp = defaultdict(int)
for i in a:
	mp[i] += 1
q = deque()
a = [0] + a
res = []
j = 0
vis = defaultdict(int)
for i in range(n + 1):
	if mp[i]:
		while mp[i]:
			if len(q) > 0:
				mp[i] -= 1
				tmp = q.popleft()
				res.append(tmp)
				vis[tmp] += 1
			else:
				while mp[j] or vis[j]:
					j += 1
				vis[j] += 1
				res.append(j)
				j += 1
				mp[i] -= 1
		q.append(i)
print(*res)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = [-1 for k in range(n)]
existe = [False for k in range(100005)]
for k in range(n):
	if a[k] != a[k - 1] and k != 0:
		b[k] = a[k - 1]
		existe[b[k]] = True
existe[a[n - 1]] = 1
m = 0
for k in range(n):
	while existe[m]:
		m += 1
	if b[k] == -1:
		b[k] = m
		existe[m] = True
	print(b[k], end=' ')


import sys
input = sys.stdin.readline
from bisect import bisect_left
n = int(input())
A = list(map(int, input().split()))
SA = set(A)
erase = [i for i in range(2 * 10 ** 5 + 1) if i not in SA]
ei = 0
B = [-1] * n
mex = 0
prev = 0
for (i, v) in enumerate(A):
	if v != prev:
		B[i] = prev
		if prev == erase[ei]:
			ei += 1
	else:
		B[i] = erase[ei]
		ei += 1
	if erase[ei] < v:
		print(-1)
		sys.exit(0)
	prev = v
print(' '.join(map(str, B)))


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 1
t = set(a)
for i in a:
	if i == x:
		while y in t:
			y += 1
		print(y, end=' ')
		y += 1
	else:
		print(x, end=' ')
		x = i


n = int(input())
arr = list(map(int, input().split()))
used = [0 for i in range(10 ** 6 + 1)]
b = [-1 for i in range(n)]
used[arr[0]] = 1
for i in range(1, n):
	if arr[i] > arr[i - 1]:
		used[arr[i]] = 1
		b[i] = arr[i - 1]
m = 0
for i in range(n):
	while used[m] != 0:
		m += 1
	if b[i] == -1:
		b[i] = m
		used[m] = 1
print(*b)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
b = [-1] * n
vis = [0] * (n + 1)
k = 0
vis[l[-1]] = 1
for i in range(n - 1, 0, -1):
	if l[i] != l[i - 1]:
		b[i] = l[i - 1]
		vis[l[i - 1]] = 1
for i in range(n):
	if b[i] == -1:
		while vis[k] == 1:
			k += 1
		b[i] = k
		k += 1
print(*b)


a = int(input())
b = [int(x) for x in input().split()]
impo = 0
uniq = []
notyet = []
if b[0] != 0:
	notyet.append([0, b[0]])
k = [-1] * a
for i in range(a):
	if i + 1 < b[i]:
		impo = 1
		break
	if b[i] > b[i - 1]:
		k[i] = b[i - 1]
		uniq.append(k[i])
		if b[i] - b[i - 1] != 1:
			notyet.append([b[i - 1] + 1, b[i]])
notyeti = 0
lack = 0
if impo == 1:
	print(-1)
else:
	for i in range(a):
		if k[i] == -1:
			if notyeti < len(notyet):
				k[i] = notyet[notyeti][0]
				notyet[notyeti][0] += 1
				if notyet[notyeti][0] == notyet[notyeti][1]:
					notyeti += 1
			else:
				k[i] = b[-1] + 1
	for i in k:
		print(i, end=' ')
	print()


n = int(input())
m = 0
p = 0
c = []
d = []
b = [int(a) for a in input().split()]
for i in range(0, n):
	if b[i] == m:
		if m == 0:
			c.append(1)
		else:
			c.append(m - 1)
		d.append(i)
	elif b[i] < m:
		p = 1
		break
	else:
		k = b[i] - m
		k -= 1
		c.append(m)
		m += 1
		if k:
			if len(d) < k:
				p = 1
				break
			else:
				while k > 0:
					h = d.pop()
					k -= 1
					c[h] = m
					m += 1
while len(d) > 0:
	h = d.pop()
	c[h] = m + 1
	m += 1
if p:
	print(-1)
else:
	for i in c:
		print(i, end=' ')
	print()


N = int(input())
A = list(map(int, input().split()))
mp = {}
for i in range(N):
	mp[A[i]] = i
curr = 0
B = []
for i in range(N):
	if i > 0 and A[i] != A[i - 1]:
		B.append(A[i - 1])
		curr = max(A[i - 1] + 1, curr)
	else:
		while 1 == 1:
			if curr in mp and mp[curr] >= i:
				curr += 1
			else:
				break
		B.append(curr)
		curr += 1
for b in B:
	print(b, end=' ')
print('')


n = int(input())
l = list(map(int, input().split()))
totalmax = max(l)
s = set(range(l[-1]))
flag = True
ans = [0] * n
reduntspots = []
for i in range(n):
	if l[i] > i + 1:
		print(-1)
		flag = False
		break
	if l[i] in s:
		s.remove(l[i])
	if i == 0 and l[i] != 0:
		ans[i] = 0
	if i != 0 and l[i] != l[i - 1]:
		ans[i] = l[i - 1]
		continue
	reduntspots.append(i)
if flag:
	if len(s) <= len(reduntspots):
		missinglist = list(sorted(s)) + [totalmax + 1] * (len(reduntspots) - len(s))
		for i in range(len(reduntspots)):
			ans[reduntspots[i]] = missinglist[i]
		print(*ans)
	else:
		print(-1)


n = int(input())
a = list(map(int, input().split()))
ok = a[0] - 1 <= 0
for i in range(1, n):
	if a[i] - 1 > i:
		ok = False
	if a[i] < a[i - 1]:
		ok = False
if ok == False:
	print(-1)
	quit()
m = set(a)
b = []
s = 0
for i in range(s, n + 10):
	if i not in m:
		b.append(i)
		s = i + 1
		break
for i in range(1, n):
	if a[i] != a[i - 1]:
		b.append(a[i - 1])
		continue
	for j in range(s, n + 10):
		if j not in m:
			b.append(j)
			s = j + 1
			break
for i in range(n):
	print(b[i], end=' ')


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split()))
ans = [-1] * n
s1 = set(l)
s2 = set()
raj = 0
abc = 0
for i in range(n + 1):
	if i not in s1:
		s2.add(i)
for i in range(1, n):
	if l[i] != l[i - 1]:
		ans[i] = l[i - 1]
bln = sorted(s2)
t = 0
for i in range(n):
	if ans[i] == -1:
		ans[i] = bln[t]
		t += 1
print(*ans)


def f(n, l):
	if l[0] > 1:
		return -1
	skipped = []
	output = ['-'] * n
	lowestpossible = 0
	highestpossible = l[-1]
	for i in range(n):
		if l[i] > lowestpossible:
			output[i] = lowestpossible
			skipped += list(range(lowestpossible + 1, l[i]))
			lowestpossible = l[i]
	for i in range(n):
		if output[i] == '-':
			if len(skipped) == 0:
				output[i] = highestpossible + 1
			else:
				output[i] = skipped.pop(0)
	return ' '.join([str(t) for t in output])
n = int(input())
l = [int(t) for t in input().split()]
print(f(n, l))


from sys import stdin as cin
lmap = lambda f, v: list(map(f, v))

def mexarray(a):
	missing = list(sorted(set(range(1, len(a) + 1)) - set(a), reverse=True))
	a = [0] + a
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			yield missing.pop()
		else:
			yield a[i - 1]

def main():
	n = lmap(int, next(cin).strip().split())
	a = lmap(int, next(cin).strip().split())
	print(' '.join(map(str, mexarray(a))))
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(1):
	n = int(input())
	num = list(map(int, input().split()))
	num1 = set(num)
	temp = set()
	for i in range(n + 1):
		if i not in num1:
			temp.add(i)
	num1 = list(temp)
	num1.sort()
	ans = [num1[0]]
	ctr = 1
	for i in range(1, n):
		if num[i] != num[i - 1]:
			ans.append(num[i - 1])
		else:
			ans.append(num1[ctr])
			ctr += 1
	print(*ans)


FAST_IO = 1
if FAST_IO:
	import io, sys, atexit
	read = iter(sys.stdin.read().splitlines()).__next__
	_OUTPUT_BUFFER = io.StringIO()
	sys.stdout = _OUTPUT_BUFFER

	@atexit.register
	def write():
		sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
	read = input
readint = lambda : int(read())
readlist = lambda : list(map(int, read().split()))

def solve(N, A):
	free = []
	ans = [10 ** 6] * N
	low = 0
	for i in range(N):
		free.append(i)
		while free and low < A[i]:
			j = free.pop()
			ans[j] = low
			low += 1
	return ans
N = readint()
A = readlist()
ans = solve(N, A)
if ans is None:
	print(-1)
else:
	print(' '.join(map(str, ans)))


n = int(input())
a = tuple(map(int, input().split()))
sa = set(a)
san = set()
min_not_in = 0
prev = 0
ans = [0] * n
for i in range(n):
	cur = a[i]
	if cur == prev:
		while min_not_in in sa:
			min_not_in += 1
		ans[i] = min_not_in
		sa.add(min_not_in)
		san.add(min_not_in)
	else:
		ans[i] = prev
		sa.add(prev)
		san.add(prev)
		while prev in san:
			prev += 1
		if cur != prev:
			print(-1)
			break
else:
	print(*ans)


from sys import stdin
from collections import deque
n = int(stdin.readline())
a = list(map(int, stdin.readline().strip().split()))
c = set(a)
d = deque()
for i in range(n + 1):
	if i not in c:
		d.append(i)
b = []
for i in range(n):
	if i != 0:
		if a[i - 1] < a[i]:
			b.append(a[i - 1])
		else:
			b.append(d.popleft())
	else:
		b.append(d.popleft())
print(*b)


import queue
import math
n = int(input())
a = list(map(int, input().split()))
b = [-1 for i in range(n)]
prev = 0
for i in range(n):
	if a[i] != prev:
		b[i] = prev
	prev = a[i]
s = set([i for i in range(a[-1])])
for x in b:
	s.discard(x)
s = list(s)
s.append(n + 1)
idx = 0
for i in range(n):
	if b[i] == -1:
		if idx < len(s):
			b[i] = s[idx]
			idx += 1
		else:
			b[i] = s[-1]
for x in b:
	print(x, end=' ')
print()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a = [0] + a
cnt = 0
x = []
for i in range(n):
	if a[i + 1] - a[i] >= 2:
		cnt += -(a[i + 1] - a[i]) + 1
		for j in range(a[i] + 1, a[i + 1]):
			x.append(j)
	elif a[i + 1] == a[i]:
		cnt += 1
	if cnt < 0:
		print(-1)
		exit()
ans = [0] * n
cnt = 0
for i in range(n):
	if a[i + 1] - a[i] == 1:
		ans[i] = a[i]
	elif cnt < len(x) and a[i + 1] == a[i]:
		ans[i] += x[cnt]
		cnt += 1
	elif a[i + 1] - a[i] >= 2:
		ans[i] = a[i]
	else:
		ans[i] = pow(10, 6)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
x = []
m = []
p = []
ans = []
flag = 0
if a[0] > 1:
	flag = 1
else:
	for i in range(1, n):
		if a[i] > i + 1:
			flag = 1
			break
		else:
			d = a[i] - a[i - 1]
			x.append(d)
			if d > 1:
				m.append(d - 1)
				p.append(a[i])
	if a[0] == 1:
		ans.append(0)
	elif len(p) != 0:
		ans.append(p[0] - m[0])
		m[0] -= 1
		if m[0] == 0:
			m.pop(0)
			p.pop(0)
	else:
		ans.append(a[n - 1] + 1)
	for i in range(1, n):
		if x[i - 1] > 0:
			ans.append(a[i - 1])
		elif len(p) != 0:
			ans.append(p[0] - m[0])
			m[0] -= 1
			if m[0] == 0:
				m.pop(0)
				p.pop(0)
		else:
			ans.append(a[n - 1] + 1)
if flag == 1:
	print(-1)
else:
	for i in range(len(ans)):
		print(ans[i], end=' ')


n = int(input())
l = [int(j) for j in input().split()]
mx = max(l) + 1
pre = ['#' for i in range(n + 1)]
c = [False for i in range(n + 1)]
for i in range(n - 1):
	if l[i] != l[i + 1]:
		pre[i + 1] = l[i]
		c[l[i]] = True
pre[n] = l[n - 1]
c[l[n - 1]] = True
s = []
for i in range(n + 1):
	if not c[i]:
		s.append(i)
j = 0
for i in range(n):
	if pre[i] == '#':
		pre[i] = s[j]
		j += 1
print(' '.join(map(str, pre[:-1])))


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = int(input())
a = list(map(int, input().split()))
s = set(a)
ans = []
ele = 0
for i in range(n):
	if i > 0 and a[i] != a[i - 1]:
		ans.append(a[i - 1])
		continue
	while ele in s:
		ele += 1
	ans.append(ele)
	ele += 1
print(*ans)


import os
import heapq
import sys
import bisect
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	arr = inar()
	res = [-1] * (n + 1)
	value = [0] * (10 ** 5 + 5)
	arr.insert(0, 0)
	lst = 0
	for i in range(1, n + 1):
		if arr[i] != arr[i - 1]:
			res[i] = arr[i - 1]
			value[arr[i - 1]] = 1
	value[arr[n]] = 1
	m = 0
	for i in range(1, n + 1):
		while value[m]:
			m += 1
		if res[i] == -1:
			res[i] = m
			value[m] = 1
	print(*res[1:n + 1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	test = 1
	for _ in range(test):
		n = int(input())
		ara = [int(num) for num in input().split()]
		mark = [True for _ in range(n + 1)]
		for num in ara:
			mark[num] = False
		take_from = []
		for index in range(n + 1):
			if mark[index]:
				take_from.append(index)
		ans = []
		ans.append(take_from[0])
		take_at = 1
		take_size = len(take_from)
		for index in range(1, n):
			if ara[index] != ara[index - 1]:
				ans.append(ara[index - 1])
			elif take_at < take_size:
				ans.append(take_from[take_at])
				take_at += 1
			else:
				ans.append(n + 1)
		ans = ' '.join(map(str, ans))
		print(ans)
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math as mt
from collections import deque

def main():
	tc = 1
	for _ in range(tc):
		n = ri()
		a = ria()
		b = [0] * n
		vis = [0] * n * 10
		nonvis = []
		f = 0
		for i in range(n):
			vis[a[i]] = 1
			if a[i] > i + 1:
				print(-1)
				f = 1
				break
		if f == 0:
			for i in range(len(vis)):
				if vis[i] != 1:
					nonvis.append(i)
			nonvisd = deque(nonvis)
			print(nonvisd.popleft(), end=' ')
			for i in range(1, n):
				if a[i - 1] != a[i]:
					print(a[i - 1], end=' ')
				else:
					print(nonvisd.popleft(), end=' ')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
use = [False] * (n + 1)
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		use[a[i - 1]] = True
use[a[n - 1]] = True
ind = 0
i = 0
while ind < n:
	if b[ind] == -1:
		while use[i] == True:
			i += 1
		b[ind] = i
		use[i] = True
		ind += 1
	else:
		ind += 1
print(*b)


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
m = 1000000007
n = ii()
a = ll()
m = [0] * 1000001
c = [0] * 1000001
for i in a:
	c[i] += 1
p = 0
q = []
ans = []
for i in range(n + 1):
	if c[i] == 0:
		continue
	while c[i]:
		if q:
			c[i] -= 1
			ans.append(q[0])
			m[q[0]] += 1
			q.pop(0)
		else:
			while c[p] or m[p]:
				p += 1
			m[p] += 1
			ans.append(p)
			p += 1
			c[i] -= 1
	q.append(i)
print(*ans)


n = int(input())
mas = list(map(int, input().split()))
ans = []
have = [0 for i in range(1000009)]
for i in range(n):
	if i > 0 and mas[i - 1] != mas[i]:
		ans.append(mas[i - 1])
		have[mas[i - 1]] = 1
	else:
		ans.append(-1)
j = 0
have[mas[n - 1]] = 1
for i in range(len(ans)):
	if ans[i] == -1:
		while have[j]:
			j += 1
		ans[i] = j
		have[j] = 1
if mas[0] > 1:
	print(-1)
else:
	for x in ans:
		print(x, end=' ')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
n = iinput()
a = get_list()
s = set(a)
ans = []
ele = 0
for i in range(n):
	if i > 0 and a[i] != a[i - 1]:
		ans.append(a[i - 1])
	else:
		while ele in s:
			ele += 1
		ans.append(ele)
		ele += 1
print(*ans)


from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
l1 = []
d = defaultdict(int)
for x in l:
	d[x] = 1
ma = 1
if l[0] == 0:
	while d[ma] != 0:
		ma += 1
	d[ma] = 1
	l1.append(ma)
	m = 0
elif l[0] == 1:
	l1.append(0)
	m = 1
	ma = 2
else:
	f = 1
	sys.exit(0)
f = 0
for x in range(1, n):
	if l[x] == m:
		while d[ma] != 0:
			ma += 1
		d[ma] = 1
		l1.append(ma)
	else:
		if l[x] > ma + 1:
			f = 1
			break
		l1.append(m)
		m = l[x]
		ma = max(ma, m)
if f == 1:
	print(-1)
else:
	for x in l1:
		print(x, end=' ')


import math
import heapq, bisect
import sys
from collections import deque
from fractions import Fraction
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [-1] * n
	r = set(l)
	r1 = set()
	for i in range(n + 1):
		if i not in r:
			r1.add(i)
	for i in range(1, n):
		if l[i] != l[i - 1]:
			ans[i] = l[i - 1]
	mis = sorted(r1)
	t = 0
	for i in range(n):
		if ans[i] == -1:
			ans[i] = mis[t]
			t += 1
	print(*ans, sep=' ')


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
ans = []
ok = True
s = set(a)
now = 1
p = 0
for i in a:
	if i != p:
		ans.append(p)
		p = i
	else:
		while now in s:
			now += 1
		ans.append(now)
		now += 1
print(*ans)


from collections import Counter
input()
for sjdkla in range(1):
	arr = list(map(int, input().split()))
	count = Counter(arr)
	prev = arr[0]
	impossible = False
	for (ind, i) in enumerate(arr):
		if i > ind + 1:
			impossible = True
		break
	if impossible:
		print(-1)
		continue
	newarr = []
	newset = set()
	safe = 0
	newsafe = None
	while 1:
		if count[safe] == 0:
			break
		safe += 1
	for i in arr:
		if newsafe is not None:
			newarr.append(newsafe)
			newsafe = None
		else:
			newarr.append(safe)
			while 1:
				safe += 1
				if count[safe] == 0:
					break
		count[i] -= 1
		if count[i] == 0:
			newsafe = i
	print(*newarr)


n = int(input())
a = list(map(int, input().split()))
b = []
s = set(a)
(bi1, bi2) = (0, 1)
for i in range(n):
	if a[i] != bi1:
		b.append(bi1)
		if bi2 == a[i]:
			bi2 += 1
	else:
		while bi2 in s:
			bi2 += 1
		b.append(bi2)
		bi2 += 1
	bi1 = a[i]
print(*b)


n = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
output = [-1] * (n + 1)
flag = 0
last = 0
for (i, a) in enumerate(A):
	if a > i + 1:
		flag = 1
		break
	if i > 0:
		if A[i] > A[i - 1]:
			output[i] = A[i - 1]
if flag:
	print(-1)
else:
	j = 1
	while j < n + 1 and output[j] != -1:
		j += 1
	for (i, o) in enumerate(output):
		if o != -1:
			for k in range(o + 1, A[i]):
				output[j] = k
				while j < n + 1 and output[j] != -1:
					j += 1
	for i in range(1, len(output)):
		o = output[i] if output[i] != -1 else A[n] + 1
		print(o, end=' ')
	print()


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0 for i in range(n)]
	smallest = []
	s = 0
	while s < arr[0]:
		smallest.append(s)
		s += 1
	s = arr[0] + 1
	if n == 1:
		smallest.append(s)
	for i in range(1, n):
		while s < arr[i]:
			smallest.append(s)
			s += 1
		s = arr[i] + 1
		if i == n - 1:
			smallest.append(s)
	j = 0
	for i in range(n):
		if arr[i] > arr[i - 1]:
			ans[i] = arr[i - 1]
		else:
			if j < len(smallest):
				ans[i] = smallest[j]
				last = smallest[j]
			else:
				ans[i] = last
				last += 1
			j += 1
	print(*ans)
t = 1
for _ in range(t):
	main()


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
s = [l[0]]
d = dd(int)
d[l[0]] += 1
for i in range(1, n):
	if l[i] != l[i - 1]:
		s.append(l[i])
	d[l[i]] += 1
i = 0
nn = len(s)
res = []
nums = 0
prev = -1
k = 0
while i < n:
	if l[i] != prev and prev != -1:
		res.append(prev)
		prev = l[i]
	else:
		while d[k] != 0:
			k += 1
		res.append(k)
		k += 1
		prev = l[i]
	i += 1
print(*res)


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def get_min(a, b):
	(v1, c1) = a
	(v2, c2) = b
	if v1 < v2:
		return b
	elif v1 > v2:
		return a
	elif c1 < c2:
		return a
	else:
		return b

def main():
	t = 1
	while t:
		t -= 1
		n = iin()
		a = lin()
		sa = set(a)
		b = []
		ch1 = 0
		for i in range(n):
			if i > 0 and a[i] != a[i - 1]:
				b.append(a[i - 1])
				continue
			while ch1 in sa:
				ch1 += 1
			b.append(ch1)
			ch1 += 1
		print(*b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


n = int(input())
a = list(map(int, input().split()))
b = [-1] * (n + 1)
a.append(-1)
f = 0
d = set()
for i in range(1, n + 1):
	if a[i - 1] != a[i]:
		b[i] = a[i - 1]
		d.add(b[i])
d = list(set(list(range(n + 1))) - d)
c = 0
for i in range(n + 1):
	if b[i] == -1:
		b[i] = d[c]
		c += 1
print(*b[:-1])


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n):
	pre = [0] * n
	pre[0] = a[0]
	for i in range(1, n):
		pre[i] = a[i] + pre[i - 1]
	return pre
n = inin()
l = ain()
ans = [i for i in range(n + 1)]
for i in range(n - 1, -1, -1):
	if ans[i] >= l[i]:
		(ans[i + 1], ans[l[i]]) = (ans[l[i]], ans[i + 1])
print(*ans[:n])


n = int(input())
a = list(map(int, input().split()))
b = [-1] * n
v = [-1] * (n + 1)
f = 0
v[a[n - 1]] = 1
for i in range(n - 1, 0, -1):
	if a[i] > i + 1:
		f = 1
		break
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		v[a[i - 1]] = 1
if f == 1:
	print(-1)
vi = []
for i in range(len(v)):
	if v[i] == -1:
		vi.append(i)
j = 0
for i in range(len(b)):
	if b[i] == -1:
		b[i] = vi[j]
		j += 1
print(*b)


import sys, math
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 998244353
n = int(data())
a = mdata()
s = set(a)
d = dd(int)
for i in range(n):
	d[a[i]] = i
cnt = 0
ans = []
k = 0
for i in range(n):
	while True:
		if cnt in s:
			cnt += 1
		else:
			break
	if k == 0:
		ans.append(cnt)
		if d[a[i]] == i:
			ans.append(a[i])
			k = 1
		cnt += 1
	elif d[a[i]] == i:
		ans.append(a[i])
	else:
		k = 0
if len(ans) > n:
	ans.pop()
print(*ans)


from collections import deque
from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a):
	result = [None] * n
	items_in_a = set(a)
	curr = 0
	for i in range(n):
		if i > 0 and a[i - 1] != a[i]:
			result[i] = a[i - 1]
		else:
			while curr in items_in_a:
				curr += 1
			result[i] = curr
			curr += 1
	return result
n = int_in()
a = arr_in()
arr_out(solve(n, a))


input()
maybe_used = []
data = list(map(int, input().split()))
result = [None] * len(data)
if data[0] == 0:
	maybe_used.append(0)
elif data[0] == 1:
	result[0] = 0
else:
	print(-1)
break_flag = False
for i in range(1, len(data)):
	if data[i] == data[i - 1]:
		maybe_used.append(i)
	elif data[i] == data[i - 1] + 1:
		result[i] = data[i - 1]
	else:
		result[i] = data[i - 1]
		for j in range(data[i - 1] + 1, data[i]):
			if maybe_used:
				k = maybe_used.pop(0)
				result[k] = j
				pass
			else:
				break_flag = True
				break
		if break_flag:
			print(-1)
			break
if not break_flag:
	x = 100500
	while maybe_used:
		result[maybe_used.pop(0)] = x
		x += 1
	print(*result)
	pass


import sys
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)
readline = sys.stdin.readline
n = int(readline())
a = list(map(int, readline().split()))
b = [-1] * n
not_visited = []
visited = [-1] * 10 ** 6
flag = True
for (i, j) in enumerate(a):
	if j > i + 1:
		flag = False
		break
	visited[j] = 1
if not flag:
	print(-1)
	sys.exit(0)
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
for (i, j) in enumerate(visited):
	if j == -1:
		not_visited.append(i)
k = 0
for (i, j) in enumerate(b):
	if j == -1:
		b[i] = not_visited[k]
		k += 1
print(*b)


import os
import sys
from io import BytesIO, IOBase
import math

def inputIntArray():
	return list(map(int, input().rstrip().split()))

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(1):
		n = inputNum()
		arr = [0] + inputIntArray()
		ansArr = [-1] * (n + 1)
		usedArrValues = [False] * 10 ** 6
		for pos in range(1, n + 1):
			if arr[pos] != arr[pos - 1]:
				ansArr[pos] = arr[pos - 1]
				usedArrValues[ansArr[pos]] = True
		usedArrValues[arr[-1]] = True
		tempPos = 0
		for pos in range(1, n + 1):
			while usedArrValues[tempPos]:
				tempPos += 1
			if ansArr[pos] == -1:
				ansArr[pos] = tempPos
				usedArrValues[tempPos] = True
			print(ansArr[pos], end=' ')
		print(' ')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l = list(map(int, input().split()))
ans = []
neg = []
till = -1
for i in range(n):
	if till == l[i] - 1:
		ans.append(-1)
		neg.append(i)
	else:
		till += 1
		ans.append(till)
		while till != l[i] - 1 and len(neg):
			ind = neg.pop()
			till += 1
			ans[ind] = till
ma = max(l)
while len(neg):
	ind = neg.pop()
	ans[ind] = ma + 1
print(*ans)


import sys
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
s = set(a)
bs = [0] * n
at = 0
for i in range(n):
	while at in s:
		at += 1
	bs[i] = at
	at += 1
ans = [0] * n
used = 0
for i in range(n):
	if i != 0 and a[i] != a[i - 1]:
		ans[i] = a[i - 1]
	else:
		ans[i] = bs[used]
		used += 1
print(' '.join([str(i) for i in ans]))


import sys
input = sys.stdin.readline
import math

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())

def from_file(f):
	return f.readline

def solve(n, A):
	S = set(A)
	next_num = 0
	memory = A[0]
	b = []
	for (i, ai) in enumerate(A):
		if ai != memory:
			if memory == ai - 1 or next_num >= ai:
				b.append(memory)
				memory = ai
			else:
				return None
		else:
			while next_num in S:
				next_num += 1
			b.append(next_num)
			next_num += 1
	return b
n = inp()
A = inlt()
b = solve(n, A)
if b:
	print(' '.join(map(str, b)))
else:
	print('-1')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [10 ** 6] * n
	unf = 0
	cur = 0
	for i in range(n):
		if a[i] > cur:
			omega = a[i] - 1
			alpha = cur
			ans[i] = alpha
			while alpha < omega:
				while ans[unf] != 10 ** 6:
					unf += 1
				ans[unf] = omega
				omega -= 1
				unf += 1
			cur = a[i]
	print(*ans)


n = int(input())
b = [int(i) for i in input().split()]
ans = [-1] * n
visited = [0] * (n + 1)
for i in range(1, n):
	if b[i] != b[i - 1]:
		visited[b[i - 1]] = 1
		ans[i] = b[i - 1]
visited[b[-1]] = 1
count = 0
for i in range(len(ans)):
	if ans[i] == -1:
		while visited[count] == 1:
			count += 1
		ans[i] = count
		visited[count] = 1
print(*ans)


import heapq
t = 1
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	seen = set()
	for i in range(n):
		if arr[i] > 1 + i:
			print(-1)
			t -= 1
			continue
		seen.add(arr[i])
	h = []
	for i in range(n + 1):
		if i not in seen:
			heapq.heappush(h, i)
	ans = []
	for i in range(n):
		if i > 0 and arr[i] != arr[i - 1]:
			heapq.heappush(h, arr[i - 1])
		ans.append(heapq.heappop(h))
	print(' '.join([str(i) for i in ans]))
	t -= 1


n = int(input())
a = list(map(int, input().rstrip().split()))
freq = dict()
for el in a:
	freq[el] = freq.get(el, 0) + 1
pos = list()
for i in range(0, 2 * n + 2):
	if i not in freq:
		pos.append(i)
res = [0 for i in range(n)]
punt = 0
for i in range(n):
	if i == 0 or freq[a[i - 1]] > 0:
		res[i] = str(pos[punt])
		punt += 1
	else:
		res[i] = str(a[i - 1])
	freq[a[i]] -= 1
print(' '.join(res))


n = int(input())
A = list(map(int, input().split()))
S = set(range(n + 1))
S.remove(A[-1])
used = set()
used.add(A[-1])
B = [-1] * n
H = list(range(n + 1))
H = [-x for x in H]
import heapq
heapq.heapify(H)
for i in reversed(range(n)):
	if i != 0:
		if A[i - 1] not in used:
			B[i] = A[i - 1]
			used.add(A[i - 1])
		else:
			while H:
				x = heapq.heappop(H) * -1
				if x not in used:
					break
			B[i] = x
			used.add(x)
	else:
		while H:
			x = heapq.heappop(H) * -1
			if x not in used:
				break
		B[i] = x
		used.add(x)
print(*B)


n = int(input())
l = list(map(int, input().split()))
ni = [0] * (n + 1)
for i in l:
	ni[i] = 1
el = []
for i in range(0, n + 1):
	if ni[i] == 0:
		el.append(i)
a = [el[0]]
ind = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		a.append(el[ind])
		ind += 1
	else:
		a.append(l[i - 1])
print(*a)


import heapq

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = [10 ** 6] * n
	for i in range(n):
		if a[i] > i + 1:
			print(-1)
			return
	c = [list() for _ in range(n)]
	for i in range(n - 1, 0, -1):
		if a[i] == a[i - 1]:
			continue
		for j in range(a[i - 1], a[i]):
			c[i].append(j)
	for j in range(a[0]):
		c[0].append(j)
	r = []
	for i in range(n - 1, -1, -1):
		if c[i]:
			for j in c[i]:
				heapq.heappush(r, j)
		if r:
			b[i] = heapq.heappop(r)
	print(*b)
solve()


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
d = dict()
for j in range(n):
	if a[j] in d.keys():
		d[a[j]] += 1
	else:
		d[a[j]] = 1
		c.append(a[j])
j = 0
i = 0
while j < len(c):
	p = c[j]
	k = d[c[j]]
	if j != 0:
		b.append(c[j - 1])
		k -= 1
	p = 0
	while p < k:
		if i in d.keys():
			pass
		else:
			b.append(i)
			p += 1
		i += 1
	j += 1
if max(b) > 10 ** 6:
	print(-1)
else:
	print(*b)


import math as ma
n = int(input())
a = list(map(int, input().split()))
e = 0
for i in range(n):
	if a[i] - i - 1 > 0:
		e = 1
		print(-1)
		break
if e == 0:
	b = [-1] * n
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			b[i + 1] = a[i]
	c = set(a)
	d = []
	for i in range(2 * 10 ** 5):
		if i not in c:
			d.append(i)
	j = 0
	for i in range(n):
		if b[i] == -1:
			b[i] = d[j]
			j += 1
	print(*b)


def f(a):
	st = set(a)
	now = 1
	p = 0
	ans = []
	for i in a:
		if i != p:
			ans.append(p)
			p = i
		else:
			while now in st:
				now += 1
			ans.append(now)
			now += 1
	return ans
a = input()
lst = list(map(int, input().strip().split()))
print(*f(lst))


def solution(a):
	b = [-1] * len(a)
	d = {}
	for i in range(1, len(a)):
		if a[i] != a[i - 1]:
			b[i] = a[i - 1]
			d[b[i]] = 1
	d[a[n - 1]] = 1
	m = 0
	for i in range(0, len(a)):
		while d.get(m, 0):
			m = m + 1
		if b[i] == -1:
			b[i] = m
			d[m] = 1
	return b
n = int(input())
a = [int(x) for x in input().split()]
print(*solution(a))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
b = [-1] * (n + 1)
a.append(-1)
f = 0
d = set()
for i in range(1, n + 1):
	if a[i - 1] != a[i]:
		b[i] = a[i - 1]
		d.add(b[i])
d = list(set(list(range(n + 1))) - d)
c = 0
for i in range(n + 1):
	if b[i] == -1:
		b[i] = d[c]
		c += 1
print(*b[:-1])


n = int(input())
a = list(map(int, input().split()))
val = set([i for i in range(a[-1])])
b = [-1] * n
for i in range(1, n):
	if a[i] != a[i - 1]:
		b[i] = a[i - 1]
		val.remove(a[i - 1])
val = list(val)
ind = 0
for i in range(n):
	if b[i] == -1:
		if ind >= len(val):
			b[i] = 1000000
		else:
			b[i] = val[ind]
			ind += 1
print(*b)


n = int(input())
arr = [*map(int, input().split())]
s1 = set([*range(n + 1)])
s2 = set(arr)
s1 = s1 - s2
s1 = [*s1][::-1]
s2 = [*s2][::-1]
ans = [s1[-1]]
del s1[-1]
for i in range(1, n):
	if arr[i] != arr[i - 1]:
		ans.append(s2[-1])
		del s2[-1]
	else:
		ans.append(s1[-1])
		del s1[-1]
print(*ans)


from collections import deque
n = int(input())
mark = {}
mark1 = {}
a = list(map(int, input().split()))
t = 0
Ans = []
p = deque()
for i in a:
	mark[i] = 1
for i in a:
	if i == t:
		if len(p) > 0:
			if i == p[0]:
				while mark.get(t, None) != None:
					if mark1.get(t, None) == None:
						p.append(t)
						mark1[t] = 1
					t += 1
				Ans.append(t)
				t += 1
			else:
				q = p.popleft()
				Ans.append(q)
		else:
			while mark.get(t, None) != None:
				if mark1.get(t, None) == None:
					p.append(t)
					mark1[t] = 1
				t += 1
			Ans.append(t)
			t += 1
	elif len(p) > 0:
		if i == p[0]:
			while mark.get(t, None) != None:
				if mark1.get(t, None) == None:
					p.append(t)
					mark1[t] = 1
				t += 1
			Ans.append(t)
			t += 1
		else:
			q = p.popleft()
			Ans.append(q)
	else:
		Ans.append(t)
		t += 1
print(*Ans)


import io
import os
from collections import Counter, defaultdict, deque
import heapq
BIG = 10 ** 6

def solve(N, A):
	B = [None for i in range(N)]
	need = []
	for i in range(N - 2, -1, -1):
		x = A[i]
		y = A[i + 1]
		if x < y:
			B[i + 1] = x
			for z in range(x + 1, y):
				heapq.heappush(need, z)
		elif need:
			B[i + 1] = heapq.heappop(need)
		else:
			B[i + 1] = BIG
	if 0 < A[0]:
		if A[0] != 1:
			return -1
		B[0] = 0
	else:
		if len(need) > 1:
			return -1
		if len(need) == 1:
			B[0] = need[0]
		else:
			B[0] = BIG
	return ' '.join(map(str, B))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


from collections import deque
n = int(input())
s = [int(x) for x in input().split()]
temp = 0
for i in range(0, len(s)):
	if s[i] > i + 1:
		temp = 1
		break
if temp == 1:
	print(-1)
else:
	pos = [0] * (10 * n + 5)
	for i in range(0, len(s)):
		pos[s[i]] = 1
	b = []
	ptr = 0
	kk = 0
	dd = dict()
	for i in range(0, len(s)):
		if ptr == s[i]:
			for j in range(kk, len(pos)):
				if pos[j] == 0:
					b.append(j)
					pos[j] = 1
					dd[j] = 1
					kk = j + 1
					break
		else:
			b.append(ptr)
			dd[ptr] = 1
			pos[ptr] = 1
			for j in range(ptr + 1, len(pos)):
				if dd.get(j) == None:
					ptr = j
					break
	print(*b)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
import heapq as hp
n = int(input())
a = int_array()
mset = {i for i in range(n + 10)}
for i in a:
	if i in mset:
		mset.remove(i)
q = sorted(list(mset))
ans = []
ind = 0
while len(ans) != n:
	x = hp.heappop(q)
	ans.append(x)
	if ind != n - 1:
		if a[ind] != a[ind + 1]:
			hp.heappush(q, a[ind])
	ind += 1
print(*ans)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
s = set(a)
bs = [0] * n
at = 0
for i in range(n):
	while at in s:
		at += 1
	bs[i] = at
	at += 1
ans = [0] * n
used = 0
for i in range(n):
	if i != 0 and a[i] != a[i - 1]:
		ans[i] = a[i - 1]
	else:
		ans[i] = bs[used]
		used += 1
print(*ans)


def ss(n, l):
	if l != sorted(l) or l[-1] > n:
		return [-1]
	for i in range(n):
		if l[i] > i + 1:
			return [-1]
	v = [0 for _ in range(n + 1)]
	ans = [0 for _ in range(n)]
	j = n
	for i in range(n - 1, 0, -1):
		v[l[i]] = 1
		if l[i - 1] != l[i]:
			ans[i] = l[i - 1]
		else:
			if v[j] == 1:
				while v[j] == 1:
					j -= 1
			ans[i] = j
			j -= 1
	if l[0] == 0:
		while v[j] == 1:
			j -= 1
		ans[0] = j
	return ans
n = int(input())
l = list(map(int, input().split()))
print(*ss(n, l))


import sys
input = sys.stdin.readline

def f(i, j):
	for x in range(i + 1, j):
		s.append(x)
n = int(input())
a = list(map(int, input().split()))
b = [10 ** 6] * n
s = []
ind = []
if a[0] == 1:
	b[0] = 0
else:
	ind.append(0)
for i in range(1, n):
	if a[i] > a[i - 1]:
		b[i] = a[i - 1]
		f(a[i - 1], a[i])
	else:
		ind.append(i)
ind = ind[::-1]
for x in s:
	b[ind.pop()] = x
print(*b)


from collections import defaultdict

def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
MAX = 9999999999
n = int(input())
a = read_list()
b = []
MEX = 0
dic = defaultdict(int)
for t in a:
	dic[t] += 1
m = 0
for i in range(n):
	if a[i] != MEX:
		b.append(MEX)
		MEX = a[i]
		m = max(m, b[-1] + 1)
	else:
		for tmp in range(m, MAX):
			if dic[tmp] == 0:
				b.append(tmp)
				m = tmp + 1
				break
		dic[a[i]] -= 1
print_list(b)


import os, io
from sys import stdout
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
v1 = [False] * (n + 1)
s1 = sorted(list(set(a)), reverse=True)
for i in s1:
	v1[i] = True
tmp = 0
b = [0] * n
flag = True
for i in range(n):
	if len(s1) > 0 and a[i] > s1[-1]:
		b[i] = s1[-1]
		s1.pop()
	elif flag == True:
		if tmp == a[i] or v1[tmp] == True:
			while True:
				tmp += 1
				if tmp > n:
					flag = False
					b[i] = n + 5
					break
				if v1[tmp] == False:
					b[i] = tmp
					tmp += 1
					break
		else:
			b[i] = tmp
			tmp += 1
	else:
		b[i] = n + 5
print(*b)


n = int(input())
l = list(map(int, input().split()))
r = l[-1]
ans = [0 for i in range(n)]
d = set()
for i in range(r):
	d.add(i)
p = list(d.difference(l))
ans[0] = r + 1
if l[0] > 1:
	print(-1)
	exit()
for i in range(1, n):
	if l[i] - i > 1:
		print(-1)
		exit()
	if l[i] != l[i - 1]:
		ans[i] = l[i - 1]
	else:
		ans[i] = None
q = {}
p.sort(reverse=True)
try:
	ans[0] = p.pop()
except:
	ans[0] = r + 1
q[ans[0]] = 1
for i in range(1, n):
	if ans[i] == None:
		try:
			ans[i] = p.pop()
		except:
			ans[i] = r + 1
print(*ans)


from collections import deque
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
c = set(a)
d = deque()
for i in range(n + 1):
	if i not in c:
		d.append(i)
b = []
for i in range(n):
	if i != 0:
		if a[i - 1] < a[i]:
			b.append(a[i - 1])
		else:
			b.append(d.popleft())
	else:
		b.append(d.popleft())
print(*b)


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	n = int(ii())
	data = idata()
	slov = dict()
	for i in range(0, n + n + 12):
		slov[i] = 0
	for i in range(n):
		if data[i] > i + 1:
			print(-1)
			return
		slov[data[i]] = 1
	ans = []
	data += [n + n + 12]
	m = 0
	for i in range(n):
		if data[i] > data[i - 1] and i != 0:
			ans += [data[i - 1]]
		else:
			while slov[m]:
				m += 1
			ans += [m]
			slov[m] = 1
	print(*ans)
	return
solve_of_problem()


n = int(input())
a = list(map(int, input().strip().split()))
available_numbers = set(range(2 * n))
removed = set()
for v in a:
	if v not in removed:
		available_numbers.remove(v)
		removed.add(v)
available_numbers = sorted(list(available_numbers))
mex = [-1] * n
for (i, v) in enumerate(a[1:]):
	if a[i] != v:
		mex[i + 1] = a[i]
j = 0
for (k, v) in enumerate(mex):
	if v == -1:
		mex[k] = available_numbers[j]
		j += 1
print(' '.join(map(str, mex)))


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
from math import ceil
n = int(input())
a = list(map(int, input().split()))
s = set()
for i in range(a[-1] + 5):
	s.add(i)
for i in a:
	if i in s:
		s.remove(i)
ck = [i for i in s]
b = [ck[0]]
j = 1
for i in range(1, n):
	if a[i - 1] == a[i]:
		if j < len(ck):
			b.append(ck[j])
			j += 1
		else:
			b.append(b[-1])
	else:
		b.append(a[i - 1])
print(*b)


def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	index = n - 1
	unique = set()
	while index >= 0:
		if arr[index] > index + 1:
			print(-1)
			return
		unique.add(arr[index])
		index -= 1
	ans = []
	if arr[0] == 1:
		ans.append(0)
		unique.add(0)
	else:
		current = 0
		while current in unique:
			current += 1
		ans.append(current)
		unique.add(current)
	queue = [i for i in range(n + 1) if i not in unique]
	prev = arr[0]
	l = 1
	while l < n:
		if arr[l] != prev and arr[l - 1] in unique:
			unique.remove(arr[l - 1])
			lowest = arr[l - 1]
		else:
			lowest = queue.pop(0)
		ans.append(lowest)
		unique.add(lowest)
		prev = arr[l]
		l += 1
	print(*ans)
solve()


n = int(input())
a = list(map(int, input().split()))
b = [False] * 200000
ans = []
for i in a:
	b[i] = True
for i in range(200000):
	if not b[i]:
		ans.append(i)
print(ans[0], end=' ')
t = 1
for i in range(1, n):
	if a[i] != a[i - 1]:
		print(a[i - 1], end=' ')
	else:
		print(ans[t], end=' ')
		t += 1


def check_if_possible(values):
	for i in range(len(values)):
		if values[i] - 1 > i:
			return False
	return True

def getNextAvailable(arr, ctr):
	for i in range(ctr, len(arr)):
		if arr[i] == 1:
			arr[i] = 0
			return (i, i + 1)
n = int(input())
values = list(map(int, input().strip().split(' ')))
if check_if_possible(values):
	ansarr = [None for i in range(len(values))]
	available_values = [1 for i in range(len(values) + 1)]
	for i in values:
		available_values[i] = 0
	for i in range(1, len(values)):
		if values[i] != values[i - 1]:
			ansarr[i] = values[i - 1]
	mkr = 0
	for i in range(len(ansarr)):
		if ansarr[i] == None:
			(ansarr[i], mkr) = getNextAvailable(available_values, mkr)
	for i in ansarr:
		print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = [None] * n
unused = set()
banned = set(a)
mex = 0
c = 0
for i in range(n):
	if a[i] == mex:
		while c in banned:
			c += 1
		b[i] = c
		c += 1
	else:
		if i > 0:
			banned.discard(a[i - 1])
		b[i] = mex
		if c == mex:
			c += 1
		mex = a[i]
print(*b)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	bb = [0] * n
	ap = 0
	bv = 0
	mex = 0
	ap = 0
	bv = 0
	for i in range(n):
		if i > 0 and aa[i] != aa[i - 1]:
			bb[i] = aa[i - 1]
			if aa[i] > max(bv, bb[i] + 1):
				print(-1)
				return
			bv = max(bb[i] + 1, bv)
		else:
			while ap < n and bv >= aa[ap]:
				if bv == aa[ap]:
					bv += 1
				ap += 1
			bb[i] = bv
			bv += 1
			if aa[i] > bv + 1:
				print(-1)
				return
	print(' '.join(map(str, bb)))
main()


n = int(input())
l = list(map(int, input().split()))
x = 1
prev = 0
s = set(l)
res = []
flag = True
for i in range(n):
	if i + 1 < l[i] or (i > 1 and l[i] < l[i - 1]):
		flag = False
		break
if flag:
	for i in l:
		if i != prev:
			res.append(prev)
			prev = i
		else:
			while x in s:
				x += 1
			res.append(x)
			x += 1
	print(*res)
else:
	print(-1)


from collections import deque
n = int(input())
INF = float('inf')
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))

def solve(N, A):
	free = deque()
	ans = [-1] * N
	low = 0
	for (i, x) in enumerate(A):
		free.append([i, x])
		while low < x:
			if not free:
				return
			(j, y) = free.pop()
			if low != y:
				ans[j] = low
				low += 1
			else:
				return
	while free:
		ans[free.pop()[0]] = 10 ** 6
	return ans
arr = rrm()
ans = solve(n, arr)
if ans is None:
	print - 1
else:
	print(' '.join(map(str, ans)))


n = int(input())
l = list(map(int, input().split()))
if max(l) > n:
	print(-1)
else:
	a = []
	ans = []
	for i in range(n + 1):
		a.append(-1)
		ans.append(-1)
	for i in range(n):
		a[l[i]] = i + 1
	for i in range(n + 1):
		if a[i] != -1:
			ans[a[i]] = i
	print()
	j = 0
	for i in range(n + 1):
		if ans[i] != -1:
			continue
		while a[j] != -1:
			j += 1
		ans[i] = j
		j += 1
	for i in range(n):
		print(ans[i], end=' ')


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	n = I()
	a = L()
	ans = [-1] * n
	b = [0] * (n + 1)
	if a[0] == 1:
		ans[0] = 0
		b[0] = -1
	for i in range(1, n):
		if a[i] > a[i - 1]:
			ans[i] = a[i - 1]
			b[a[i - 1]] = -1
	j = 0
	b[a[-1]] = -1
	for i in range(n):
		if ans[i] == -1:
			while b[j] == -1:
				j += 1
			ans[i] = j
			j += 1
	print(*ans)
for i in range(1):
	solve()


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
n = nn()
nums = lm()
b = [10 ** 6] * n
cur_min = 0
cur_place = 0
last = 0
bad = False
for i in range(len(nums)):
	if nums[i] == last:
		continue
	else:
		b[i] = last
		cur_min += 1
	while cur_min < nums[i] and cur_place < i:
		if b[cur_place] == 10 ** 6:
			b[cur_place] = cur_min
			cur_min += 1
			cur_place += 1
		else:
			cur_place += 1
	if not cur_min == nums[i]:
		bad = True
		break
	else:
		last = nums[i]
if bad:
	print(-1)
else:
	print(*b)


n = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(2 * n + 1)]
for i in range(n):
	B[A[i]] = 1
C = []
for i in range(len(B)):
	if B[i] == 0:
		C.append(i)
ans = [C[0]]
j = 1
mv = C[0]
flag = 0
for i in range(1, n):
	if A[i] == A[i - 1]:
		ans.append(C[j])
		j = j + 1
	else:
		ans.append(A[i - 1])
print(*ans)


import sys
readline = sys.stdin.readline
from collections import deque

def solve():
	N = int(readline())
	A = list(map(int, readline().split()))
	nonused = set(range(N + 1)) - set(A)
	q = deque(sorted(nonused))
	m = 0
	ans = [0] * N
	for i in range(N):
		if A[i] == m:
			ans[i] = q.popleft()
		else:
			ans[i] = m
			if q and q[0] == m:
				q.popleft()
			m = A[i]
	print(*ans)
solve()


R = lambda : map(int, input().split())
n = int(input())
arr = list(R()) + [0]
res = [-1] * (n + 1)
slots = []
for i in range(n):
	slots.append(i)
	if arr[i] != arr[i - 1]:
		cur = arr[i - 1]
		while slots and cur < arr[i]:
			res[slots.pop()] = cur
			cur += 1
		if cur != arr[i]:
			print(-1)
			exit(0)
print(' '.join(map(str, [x if x != -1 else 10 ** 6 for x in res[:n]])))


import sys
from heapq import heappush, heappop, heapify
from collections import defaultdict

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
MAX = 10 ** 6
ok = [0] * (MAX + 1)
for (i, a) in enumerate(A):
	ok[a] = i + 1
adjli = defaultdict(list)
for (a, i) in enumerate(ok):
	adjli[i].append(a)
que = []
ans = [0] * N
for i in range(N):
	for a in adjli[i]:
		heappush(que, a)
	if not que:
		print(-1)
		exit()
	ans[i] = heappop(que)
print(*ans)


n = int(input())
czy = 0
(T, A, N, P) = ([0], [0], [0], [0])
T += map(int, input().split())
for i in range(1, n + 1):
	A.append(-1)
	if T[i] > i:
		czy = 1
	N.append(i + 1)
	P.append(i - 1)
N.append(0)
P.append(0)
if czy:
	print(-1)
	exit()
for i in range(1, n + 1):
	x = T[i] - T[i - 1]
	ile = T[i - 1]
	s = i
	for j in range(1, x + 1):
		A[s] = ile
		ile += 1
		P[N[s]] = P[s]
		N[P[s]] = N[s]
		s = P[s]
for i in range(1, n + 1):
	if A[i] == -1:
		A[i] = 1000000
s = ''
for i in range(1, n + 1):
	s += str(A[i]) + ' '
print(s)


def solve(a):
	n = len(a)
	doable = True
	for i in range(n):
		if a[i] > i + 1:
			doable = False
			break
	if doable:
		renegades = []
		for i in range(1, n):
			for el in range(a[i - 1] + 1, a[i]):
				renegades.append(el)
		renegades.reverse()
		ans = [0 for i in range(n)]
		if a[0] == 1:
			ans[0] = 0
		elif len(renegades) > 0:
			ans[0] = renegades.pop()
		else:
			ans[0] = n + 2
		for i in range(1, n):
			if a[i] == a[i - 1]:
				if len(renegades) > 0:
					ans[i] = renegades.pop()
				else:
					ans[i] = n + 2
			else:
				ans[i] = a[i - 1]
		print(' '.join([str(i) for i in ans]))
	else:
		print(-1)
n = int(input())
a = [int(i) for i in input().split()]
solve(a)