#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;
}

void solve(int l, int d, int odabrati)
{
    if(odabrati == 0) return;
    int leviMin = mini(l, d);
    if(n - leviMin >= odabrati)
    {
        mark[leviMin] = true;
        solve(leviMin+1, d, odabrati - 1);
    }
    else
    {
        int levoOdLevog = mini(l, leviMin-1);
        mark[levoOdLevog] = true;
        solve(levoOdLevog+1, d, odabrati - 1);
    }
}

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    solve(0, n-1, n-k);
    for(int i = 0; i < n; i++)
        if(mark[i]) cout << a[i] << " ";
    return 0;
}