#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
const int N=5e5+5;const int MX=32;
int n,k,a[N],b[N];
pii par[N][MX];
int getJthPar(int i,int j){
    if(j==0)return i;
    int x=min(i+(1<<(j-1)),n);
    return x;
}
pii getBest(pii p1,pii p2){
    if(p1.f!=p2.f){
        if(p1.f<p2.f)
            return p1;
        return p2;
    }
    if(p1.s<p2.s){
        return p1;
    }
    return p2;
}
pii getRangeMin(int i,int k){
    //printf("i:%d k:%d\n",i,k);
    pii best={1e9+7,0};
    ford(j,MX-1,0){
        if(k&(1<<j)){
            //printf("yes for j:%d\n",j);
            pii curr=par[i][j];
            //printf("curr:%d %d\n",curr.f,curr.s);
            best=getBest(best,curr);
            i=getJthPar(i,j)+1;
            //printf("inew:%d best:%d %d\n",i,best.f,best.s);
        }
    }
    return best;
}
void solve(int i,int left,int currCnt){
    if(currCnt==n-k){
        return;
    }
    if(i>n){
        return;
    }
    int bestInd=0,mn=1e9+7,diff=0;
    //printf("i:%d a[i]:%d left:%d\n",i,a[i],left);
    int len=min(n-i+1,left+1);
    //printf("len:%d\n",len);
    pii best=getRangeMin(i,len);
    bestInd=best.s;
    mn=a[bestInd];
    diff=bestInd-i;
    //printf("bestInd:%d\n",bestInd);
    //printf("mn:%d\n",mn);
    //printf("diff:%d\n",diff);
    /*forn(j,i,min(i+left,n)){
        //printf("  j:%d a[j]:%d\n",j,a[j]);
        if(a[j]<mn){
            mn=a[j];
            bestInd=j;
            diff=j-i;
        }
    }*/
    printf("%d ",a[bestInd]);
    solve(bestInd+1,left-diff,currCnt+1);
}
/*vector<int> bruteSolve(int i,int left,int currCnt){
    if(currCnt==n-k){
        return {};
    }
    if(i>n){
        return {};
    }
    int bestInd=0,mn=1e9+7,diff=0;
    //printf("bestInd:%d\n",bestInd);
    //printf("mn:%d\n",mn);
    //printf("diff:%d\n",diff);
    forn(j,i,min(i+left,n)){
        //printf("  j:%d a[j]:%d\n",j,a[j]);
        if(a[j]<mn){
            mn=a[j];
            bestInd=j;
            diff=j-i;
        }
    }
    //printf("%d ",a[bestInd]);
    vector<int>v=solve(bestInd+1,left-diff,currCnt+1);
    v.pb(a[bestInd]);
}*/
int main()
{
    scanf("%d%d",&n,&k);
    forn(i,1,n){
        scanf("%d",&a[i]);
    }
    forn(j,0,MX-1){
        forn(i,1,n){
            if(j==0){
                par[i][j]={a[i],i};
            }
            else{
                //printf("getJthPar(%d,%d):%d\n",i,j,getJthPar(i,j));
                par[i][j]=getBest(par[i][j-1],par[getJthPar(i,j)][j-1]);
            }
        }
    }
    /*forn(i,1,n){
        printf("i:%d\n",i);
        forn(j,0,MX-1){
            printf("j:%d par[i][j]:%d %d\n",j,par[i][j].f,par[i][j].s);
        }
    }*/
    /*forn(i,1,n){
        forn(j,1,n){
            pii rm=getRangeMin(i,j);
            printf("rangeMin(%d,%d):%d %d\n",i,j,rm.f,rm.s);
        }
    }*/
    solve(1,k,0);
    return 0;
}
/*
4 1
4 8 6 3
///
8 3
6 0 3 1 4 2 1 7
*/