#include <stdio.h>

using namespace std;

int main()
{
    int n, k;
    int a[500000];

    int obrisani = 0;

    scanf("%d%d", &n, &k);


    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);

        if(obrisani < k && a[i - 1] != -1 && a[i - 1] > a[i])
        {
            obrisani++;
            a[i - 1] = -1;

            ///DA LI JE SADA NEKO IZA VECI
            for(int j = i - 2; j >= 0; j--)
            {
                if(a[j] == -1)
                    continue;

                if(obrisani < k && a[j] > a[i])
                {
                    obrisani++;
                    a[j] = -1;
                }
                else
                    break;
            }
        }
    }

    if(obrisani < k)
    {
        int i = n - 1;
        while(obrisani != k)
        {
            if(a[i] != -1)
            {
                obrisani++;
                a[i--] = -1;
            }
            else i--;
        }
    }

    for(int i = 0; i < n; i++)
    {
        if(a[i] != -1)
            printf("%d ", a[i]);
    }

    return 0;
}