#include <bits/stdc++.h>
#define pb push_back
#define dout if(dbg) cout

using namespace std;
typedef long long ll;

bool dbg = 0;
int a[500001], mins[500001], minInds[500001];
bool mark[500001] = {0};
int n, k;

int mini(int l, int d) // indeks levog minimuma
{
    return minInds[l];
}

int mini2(int l, int d) // indeks levog minimuma
{
    int mini = a[l], minInd = l;
    for(int i = l+1; i <= d; i++)
    {
        if(a[i] < mini)
        {
            mini = a[i];
            minInd = i;
        }
    }
    return minInd;
}

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    mins[n-1] = a[n-1];
    minInds[n-1] = n-1;
    for(int i = n-2; i >= 0; i--)
    {
        if(a[i] <= mins[i+1])
        {
            mins[i] = a[i];
            minInds[i] = i;
        }
        else
        {
            mins[i] = mins[i+1];
            minInds[i] = minInds[i+1];
        }
    }

    int odabrati = n-k, l = 0, d = n-1;
    while(odabrati != 0)
    {
        int leviMin = mini(l, d);
        if(n - leviMin - 1 >= odabrati - 1)
        {
            mark[leviMin] = true;
            odabrati--;
            l = leviMin + 1;
        }
        else
        {
            int levoOdLevog = mini2(l, leviMin-1);
            mark[levoOdLevog] = true;
            odabrati--;
            l = levoOdLevog + 1;
        }
    }

    for(int i = 0; i < n; i++)
        if(mark[i]) cout << a[i] << " ";
    return 0;
}