#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#define MAX 500008
using namespace std;
int n,k,a[MAX],dp[MAX];
vector<int> b;
int popuni(int i,int j, int p, int c)
{
    if(i == j)
    {
        dp[2 * p + 1 + c] = i;
        return i;
    }
    int m = (i + j) / 2;
    int res1 = popuni(i,m,2 * p + 1 + c,0);
    int res2 = popuni(m + 1,j,2 * p + 1 + c,1);
    dp[2 * p + 1 + c] = (a[res1] <= a[res2]) ? res1 : res2;
    return dp[2 * p + 1 + c];
}

int resi(int i,int j,int p,int c,int l,int r)
{
    int now = 2 * p + 1 + c;
    if(i == l && j == r)
        return dp[now];
    int m = (i + j) / 2;
    int res,res1,res2;
    if(l <= m && r > m)
    {
        res1 = resi(i,m,now,0,l,m);
        res2 = resi(m + 1,j,now,1,m + 1,r);
        res = (a[res1] <= a[res2]) ? res1 : res2;
    }
    else if(r > m)
    {
        res2 = resi(m + 1,j,now,1,m + 1,r);
        res = res2;
    }
    else
    {
        res1 = resi(i,m,now,0,l,m);
        res = res1;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    popuni(0,n - 1,0,-1);
   // for(int j = 0; j < 7; j++)
      //  cout << dp[j] << " ";
    //cout << "\n";
    int i = 0;
    int br_ub = 0;
    int kc = k;
    if(k == 0)
    {
        for(int i = 0; i < n; i++)
            cout << a[i] << " ";
    }
    while(kc > 0 && br_ub < n - k)
    {
        int idx = resi(0,n - 1,0,-1,i,i + kc);
       // cout << idx << "\n";
        b.push_back(a[idx]);
        kc -= idx - i;
        i = idx + 1;
        if(kc == 0)
        {
            for(int j = i; j < n; j++)
            {
                b.push_back(a[j]);
            }
            break;
        }
        br_ub++;
    }
    for(int j = 0; j < (int)b.size(); j++)
        cout << b[j] << " ";
    return 0;
}