#pragma GCC optimize ("O3")
#pragma GCC optimize ("whole-program")
#pragma GCC optimize ("unroll-loops")

#include <iostream>
#include <list>
#include <set>

using namespace std;

static int n, k;
static list<pair<int, int>> a;
static set<pair<int, int>> b;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        int broj;
        cin >> broj;
        a.push_back(make_pair(broj, i));
        b.insert(make_pair(broj, i));
    }
    {
        auto i = a.begin();
        while (k && (i != a.end()))
        {
            for (auto g : b)
            {
                int asd = g.second - i->second;
                if (k >= asd)
                {
                    k -= asd;
                    {
                        auto kraj = i;
                        for (int q = 0; q < asd; q++)
                            kraj++;
                        for (auto k = i; k != kraj; k++)
                            b.erase(*k);
                        i = a.erase(i, kraj);
                    }
                    break;
                }
            }
            b.erase(*i);
            i++;
        }
    }
    if (k)
    {
        auto i = a.end();
        while (k--)
        {
            a.erase(--i);
            i = a.end();
        }

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