#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int niz[500000];

int main()
{
    int i, n, k, star, gotovo = 0;
    cin >> n >> k;
    vector<int> ignorindeks;
    for (i = 0; i < n; i++)
    {
        cin >> niz[i];

        if (i != 0)
        {
            int test = niz[i];
            int tindex = i-1;
            while ((!gotovo) && (star > test))
            {
                //cout << star << " > " << test << endl;
                ignorindeks.push_back(tindex);
                if (ignorindeks.size() == k)
                {
                    gotovo = 1;
                }
                tindex--;
                if (tindex < 0)
                    break;
                star = niz[tindex];
            }
        }

        star = niz[i];
    }

    sort(ignorindeks.begin(), ignorindeks.end());

    /*cout <<"$"<<endl;
    for (int i = 0; i < ignorindeks.size(); i++)
        cout << ignorindeks[i] << " ";
    cout << endl;*/

    for (i = 0; i < n; i++)
    {
        if (!ignorindeks.empty())
        {
            if (i == ignorindeks.at(0))
            {
                ignorindeks.erase(ignorindeks.begin()+0);
                //cout << "[S " << i << ": " << niz[i] << "] ";
                continue;
            }
        }
        cout << niz[i] << ' ';
    }

    return 0;
}