#include <iostream>
#include <list>

using namespace std;

static int n, k;
static list<int> a;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    while (n--)
    {
        int broj;
        cin >> broj;
        a.push_back(broj);
    }
    {
        auto i = a.begin();
        auto j = i;
        j++;
        while (k && (j != a.end()))
        {
            if (*i > *j)
            {
                i = a.erase(i);
                j = i;
                j++;
                k--;
            }
            else
            {
                i++; j++;
            }
        }
    }
    {
        auto i = a.end();
        while (k--)
        {
            a.erase(--i);
            i = a.end();
        }

    }
    for (auto n : a)
        cout << n << " ";
    return 0;
}