#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=2e5+5;const int MX=20;
int n,k,a[N],b[N];
pii par[N][MX];
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\n",i,a[i]);
    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);
}
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{
                par[i][j]=par[par[i][j-1].s][j-1];
            }
        }
    }*/
    solve(1,k,0);
    return 0;
}