#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 500008
using namespace std;
int n,k,a[MAX];
vector<int> b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    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 najm = INT_MAX;
        int idx = 0;
        for(int j = i; j <= i + kc; j++)
        {
            if(a[j] < najm)
            {
                najm = a[j];
                idx = j;
            }
        }
        b.push_back(najm);
        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;
}