#include <stdio.h>

using namespace std;

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int a[n];
    bool xd = false;
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        if (a[i] != 1 && a[i] != 0)
            xd = true;
    }
    if (xd){
    int b[n] = {0};
    int counter = 0;

    for (int i = 0; i < n; i++){
        a[counter] = a[i];
        b[counter] = 1;
        if (counter > 0)
        if (a[counter] == a[counter-1]){
            b[counter-1]++;
            a[counter] = -1;
            b[counter] = -1;
            counter--;
        }
        counter++;
    }
    int start = 0;
    while (k > 0){
            //YOU NEED A JUMP V MUY IMPORTANTE
        int left = 0;
        int savedI = 0;
        for (int i = counter-1; left < k; i--){
            left+=b[i];
            savedI = i;
            //printf("%d %d %d %d\n", start, savedI, left, k);   && left - k > b[start]
        }
        //printf("%d %d\n", start, savedI);
        if (savedI == start){
            //printf("el bruho");
            for (int i = counter-1; k > 0; i--){
                int temp = b[i];
                b[i]-=k;
                k-=temp;
            }
        }



        int minV = -1, minI;
        int cumulatives = 0;
        int i = start;
        while (cumulatives <= k){
            if (minV == -1 || minV > a[i]){
                minV = a[i];
                minI = i;
            }
            i++;
            cumulatives+=b[i];
            //if (cumulatives > 0)
            //printf("%d\n", cumulatives);
        }
        for (int j = minI-1; j >= start; j--){
            int temp = b[j];
            b[j]-=k;
            k-=temp;
            //printf("%d %d %d\n", j, k, b[j]);
        }
        start = minI + 1;
        //printf("k: %d\n", k);
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < b[i]; j++)
            if (b[i] > 0) printf("%d ", a[i]);
    }/*
    for (int i = 0; i < counter; i++){
        printf("%d %d\n", a[i], b[i]);
    }*/
    } else {
    bool b[n] = {false};
    int start = 0;
    while (k > 0){
        if (start + k - 1 == n){
            for (int i = start - 1; i < n; i++){
                b[i] = true;
                k--;
            }
        }
        int minV = -1, minI;
        for (int i = start; i < start + k + 1; i++){
            if (minV == -1 || minV > a[i]){
                minV = a[i];
                minI = i;
            }
        }
        for (int i = start; i < minI; i++){
            b[i] = true;
            k--;
        }
        start = minI + 1;
    }
    for (int i = 0; i < n; i++){
        if (!b[i]) printf("%d ", a[i]);
    }
    }
    return 0;

}