#include <iostream>
#include <vector>
#include <set>

using namespace std;

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

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

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