#include <iostream>
#include <stdio.h>

using namespace std;

int niz[1000000],iz[1000000];

int main()
{
    int n,k,tmp,d;
    int i;
    int tmpmin,indexmin;
    int br=1;
    int indexIz=0;
    int isBin=1;

    cin >> n >> k;
    tmp = k;
    d = n;
    for (i=0;i<n;i++){
        scanf("%d",&niz[i]);
        if ((niz[i] != 0) && (niz[i] != 1))
            isBin = 0;
    }
    //cout << isBin;
    if (isBin == 1){
        while ((tmp>0) && (tmp<d)){
            tmpmin = niz[n-d];
            indexmin = n-d;
            for(i=n-d;i<=n-d+tmp;i++){
                if (niz[i]==0){
                    tmpmin = niz[i];
                    indexmin = i;
                    break;
                }
            }
            tmp = tmp - (indexmin-(n-d));
            d = n - indexmin - 1;
            iz[indexIz] = tmpmin;
            indexIz++;
            //cout << br << ": " << tmp << " " << d << " " << tmpmin << " "  << indexmin << endl;
            br++;
        }
        if (tmp == 0){
            for (i=n-d;i<n;i++){
                iz[indexIz] = niz[i];
                indexIz++;
            }
        }
        for (i=0;i<n-k;i++){
            printf("%d ",iz[i]);
        }
    }
    else {
    //cout << "jodleihu " <<tmp<<d<<endl;
    while ((tmp>0) && (tmp<d)){
        tmpmin = niz[n-d];
        indexmin = n-d;
        for(i=n-d;i<=n-d+tmp;i++){
            if (niz[i]<tmpmin){
                tmpmin = niz[i];
                indexmin = i;
            }
        }
        tmp = tmp - (indexmin-(n-d));
        d = n - indexmin - 1;
        iz[indexIz] = tmpmin;
        indexIz++;
        //cout << br << ": " << tmp << " " << d << " " << tmpmin << " "  << indexmin << endl;
        br++;
    }
    if (tmp == 0){
        for (i=n-d;i<n;i++){
            iz[indexIz] = niz[i];
            indexIz++;
        }
    }
    /// trebalo bi da je indexIz=n-k
    //cout << indexIz << "   " << n-k << endl;
    for (i=0;i<n-k;i++){
        printf("%d ",iz[i]);
    }
    }
    return 0;
}
/*
8 3
6 0 3 1 4 2 1 7
*/