#include <bits/stdc++.h>
#define maxN 500005

using namespace std;

vector <int> v,u;
int n,i,j,t,k,a[maxN],seg[4*maxN];

int minimum(int x,int y){
if(a[x]<=a[y]) return x;
return y;
}

void build(int n,int l,int d){
if(l==d) {seg[n]=l; return;}
int m=(l+d)/2;
build(2*n,l,m);
build(2*n+1,m+1,d);
seg[n]=minimum(seg[2*n],seg[2*n+1]);
}

int query(int n,int l,int d,int x,int y){
//cout<<l<<" "<<d<<" "<<x<<" "<<y<<endl;
if(x>d || y<l) return maxN-1;
if(x<=l && y>=d) return seg[n];
int m=(l+d)/2;
return minimum(query(2*n,l,m,x,y),query(2*n+1,m+1,d,x,y));
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    for(i=0;i<v.size()-1;i++){
        if(v[i]!=v[i+1]) u.push_back(v[i]);
    }
    u.push_back(v.back());
    v.clear();
    a[maxN-1]=maxN;
    for(i=0;i<n;i++){
        int tmp=lower_bound(u.begin(),u.end(),a[i])-u.begin();
        a[i]=tmp;
    }
    build(1,0,n-1);
    for(i=0;i<n;i++){
    j=query(1,0,n-1,i,min(n-1,k+(int)v.size()));
    v.push_back(a[j]);
    i=j;
    }
    for(i=0;i<v.size();i++) cout<<u[v[i]]<<" ";
    return 0;
}