from itertools import permutations

inf = open("scanner.in", "r")
ouf = open("scanner.out", "w")

n, k = map(int, inf.readline().split())

a = list(map(int, inf.readline().split()))

kfact = 1
for i in range(1, k + 1):
    kfact *= i

ninv = [0] * kfact
perm = []
for i, z in enumerate(permutations(range(k))):
    perm.append(z)
    for p in range(k):
        for q in range(p + 1, k):
            if z[p] > z[q]:
                ninv[i] += 1

match = [set() for i in range(kfact)]

def comp(a):
    b = []
    for i in a:
        k = len(list(filter(lambda x: x < i, a)))
        b.append(k)
    return b

for i, y in enumerate(permutations(range(k))):
    for j, z in enumerate(permutations(range(k))):
        if comp(y[1:]) == comp(z[:-1]):
            match[i].add(j)

can = [[ninv[i] == a[0] and j == 0 for i in range(kfact)] for j in range(n - k + 1)]
frm = [[0 for i in range(kfact)] for j in range(n - k + 1)]

for i in range(n - k):
    for j in range(kfact):
        if can[i][j]:
            for p in match[j]:
                if ninv[p] == a[i + 1]:
                    can[i + 1][p] = True
                    frm[i + 1][p] = j

go = [set() for i in range(n)]

q = -1
for p in range(kfact):
    if can[n - k][p]:
        q = p
        break

for i in reversed(range(n - k + 1)):
    for ui, u in enumerate(perm[q]):
        for vi, v in enumerate(perm[q]):
            if u > v:
                go[i + ui].add(i + vi)
    q = frm[i][q]

index = [0 for i in range(n)]

vis = [False for i in range(n)]
cur = 1

def topsort(u):
    global cur
    vis[u] = True
    for v in go[u]:
        if not vis[v]:
            topsort(v)
    index[u] = cur
    cur += 1

for i in range(n):
    if not vis[i]:
        topsort(i)

print(" ".join(map(str, index)), file=ouf)
