#include <iostream>
#include <cstdio>

using namespace std;

int *input(int n){
    int *x = new int[n];
    for(int i = 0; i < n; i++)
        scanf("%d", x + i);
    return x;
}

bool *init(int n){
    bool *x = new bool[n];
    for(int i = 0; i < n; i++)
        x[i] = false;
    return x;
}

int min(int p, int q, int *x){
    int s = p;
    for(int i = p + 1; i <= q; i++)
        if(x[i] < x[s])
            s = i;
    return s;
}

int main(){
    int n, *x, k;
    bool *p;
    cin >> n >> k;
    x = input(n);
    p = init(n);

    k = n - k;
    for(int i = 0, j = 0; i < k; i++){
        int t = min(j, n - k + i, x);
        p[t] = true;
        j = t + 1;
    }
    for(int i = 0; i < n; i++)
        if(p[i])
            printf("%d ", x[i]);

    delete[] x;
    delete[] p;
    return 0;
}