37 lines
699 B
Python
37 lines
699 B
Python
#!/usr/bin/env python3
|
|
|
|
import heapq
|
|
|
|
def gnome_seq(A, H, n):
|
|
R = []
|
|
i = 0
|
|
while i < len(A):
|
|
if not len(H) == 0 and H[0] < A[i]:
|
|
R.append(heapq.heappop(H))
|
|
else:
|
|
R.append(A[i])
|
|
i += 1
|
|
|
|
while len(H) > 0:
|
|
R.append(heapq.heappop(H))
|
|
return R
|
|
|
|
|
|
if __name__ == "__main__":
|
|
string = input().split()
|
|
n = int(string[0])
|
|
m = int(string[1])
|
|
A = []
|
|
E = [False] * (n+1)
|
|
for i in range(m):
|
|
num = int(input())
|
|
A.append(num)
|
|
E[num] = True
|
|
H = []
|
|
for i in range(1, n + 1):
|
|
if not E[i]:
|
|
heapq.heappush(H, i)
|
|
|
|
for n in gnome_seq(A, H, n):
|
|
print(n)
|
|
|