#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];
bool mark[500001] = {0};
int n, k;

int mini(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];

    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 = mini(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;
}