#include <bits/stdc++.h>
#define MAXN 500500
using namespace std;
int a[MAXN];
int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    int pos=0;
    while(pos<n)
    {
        if(k==0) {for(int i=pos;i<n;i++)cout<<a[i]<<" ";exit(0);}
        int minpos = pos;
        for(int i=pos;i<=pos+k;i++) if(a[i]<a[minpos])minpos=i;
        cout<<a[minpos]<<" ";
        k-=minpos-pos;
        pos=minpos+1;
    }
    return 0;
}

/**
4 1
4 8 6 3

8 3
6 0 3 1 4 2 1 7
*/