#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> arr;
    int x=0;
    int mine,temp,i;
    for(i=0;i<n;i++){
        cin >>temp;
        arr.push_back(temp);
    }
    int *index=(int *) calloc(k,sizeof(int));
    int j=0;
    if(k>1){
    while(k){
        mine=arr[x];
        index[j]=x;
        for(i=x+1;i<x+k+1;i++){
            if(arr[i]<mine){
                mine=arr[i];
                index[j]=i;
            }
        }
        k-=index[j]-x;
        x=index[j]+1;
        if(x==n)
        {
            j=j+1-k;
        }
        else
            j++;
    }
    }
    else{
        int uljez=n-1;
        for(i=0;i<n-1;i++){
            if(arr[i]>arr[i+1]){
                    uljez=i;
                    i=n+1;
            }
        }
        for(i=0;i<n;i++){
            if(i!=uljez)
                cout << arr[i] << " ";
        }
        return 0;
    }
    k=0;
    for(i=0;i<n;i++){
        if(i<=index[j-1]){
            if(i==index[k]){
                cout << arr[i] <<" ";
                k++;
            }
        }
        else{
            cout << arr[i] << " ";
        }
    }
}