#include <iostream>
#include <vector>

using namespace std;

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

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

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