#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = (int) 5e5 + 100;
#ifdef LOCAL
const int SZ = N;
#else
const int SZ = (int) 1e7 + 100;
#endif
int sz;

pair <int, int> edges[SZ];
int l[SZ], r[SZ];
int edSz;
//int *degIn = r;
int degIn[SZ];

int goodSt[SZ];
int goodStSize;

int addV(int v, int tl, int tr, int pos, int val)
{
    if (tr == tl)
        return val;
   
    int cl = -1, cr = -1;
    if (v != -1)
    {
        cl = l[v];
        cr = r[v];
    }

    int nv = sz;
    l[nv] = cl;
    r[nv] = cr;
    sz++;

    int tm = (tl + tr) / 2;
    if (pos <= tm)
        l[nv] = addV(cl, tl, tm, pos, val);
    else
        r[nv] = addV(cr, tm + 1, tr, pos, val);

//    for (int to : {l[nv], r[nv]})
//        if (to != -1)
//            edges[edSz++] = make_pair(nv, to);

    return nv; 
}

void addEdges(int v, int tl, int tr, int sl, int sr, int from)
{
    if (v == -1 || sr < tl || tr < sl)
        return;

    //eprintf("addEdges(v = %d, tl = %d, tr = %d, sl = %d, sr = %d, from = %d)\n", v, tl, tr, sl, sr, from);
    if (sl <= tl && tr <= sr)
    {
        edges[edSz++] = make_pair(from, v);
        return;
    }
    int tm = (tl + tr) / 2;
    addEdges(l[v], tl, tm, sl, sr, from);
    addEdges(r[v], tm + 1, tr, sl, sr, from);
}

int p[N], pos[N];
int pans[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
        p[i]--;
        pos[p[i]] = i;
    }

    sz = n;

    memset(l, -1, sizeof l);
    memset(r, -1, sizeof r);

    int root = sz;
    //eprintf("init end\n"); 

    k--;
    for (int i = n - 1; i >= -k; i--)
    {
        //eprintf("i = %d\n", i);
        if (i >= 0)
        {
            int j = p[i];
            root = addV(root, 0, n - 1, j, i);
            //eprintf("v added\n");
        }
        
        if (k > 0 && i + k < n)
            addEdges(root, 0, n - 1, p[i + k] + 1, n - 1, i + k);
        
    }

    for (int i = 0; i < sz; i++)
    {
        if (l[i] != -1)
            degIn[l[i]]++;
            //edges[edSz++] = make_pair(i, l[i]);
        if (r[i] != -1)
            degIn[r[i]]++;
            //edges[edSz++] = make_pair(i, r[i]);
    }

//    memset(r, 0, sizeof r);

    if (sz > SZ || edSz > 2 * SZ) throw;
    //eprintf("g built\n");

    //for (int i = 0; i < edSz; i++)
    //    swap(edges[i].first, edges[i].second);
    for (int i = 0; i < edSz; i++)
    {
        //eprintf("%d -> %d\n", edges[i].first, edges[i].second);
        degIn[edges[i].second]++;
    }
    sort(edges, edges + edSz);

    priority_queue <int> good;
    for (int i = 0; i < sz; i++)
        if (degIn[i] == 0)
        {
            if (i < n)
            //eprintf("init good = %d\n", i);
                good.push(-i);
            else
                goodSt[goodStSize++] = i;
        }

    vector <int> ans;

    while (!good.empty() || goodStSize)
    {
        int v;
        if (goodStSize)
            v = goodSt[--goodStSize];
        else
        {
            v = -good.top();
            good.pop();
        }
    //    int v = *good.rbegin();
    //    if (v < n)
    //        v = *good.begin();
    //    good.erase(v);
    
    //    eprintf("v = %d\n", v);

        if (v < n)
        {
            ans.push_back(v);
        }

        int it = lower_bound(edges, edges + edSz, make_pair(v, -1)) - edges;
        while (it < edSz && edges[it].first == v)
        {
            int to = edges[it++].second;
        //for (int to : g[v])
            if (to != -1)
            {
                degIn[to]--;
                if (degIn[to] == 0)
                {
                    if (to < n)
                        good.push(-to);
                    else
                        goodSt[goodStSize++] = to;
                }
            }
        }
        for (int to : {l[v], r[v]})
            if (to != -1)
            {
                degIn[to]--;
                if (degIn[to] == 0)
                {
                    if (to < n)
                        good.push(-to);
                    else
                        goodSt[goodStSize++] = to;
                }
            }
    }

    //reverse(ans.begin(), ans.end());

    for (int i = 0; i < n; i++)
        pans[ans[i]] = i;
    for (int i = 0; i < n; i++)
        printf("%d ", pans[i] + 1);
    printf("\n");
    //for (int x : ans)
    //    printf("%d ", x + 1);
    //printf("\n");
	return 0;
}




Measured memory_bytes: 171504