#include <bits/stdc++.h>

using namespace std;

long long d[500001];

int main()
{
    long n,k,i;
    scanf("%ld%ld",&n,&k);
    long long* a=(long long*)malloc(sizeof(long long)*(n+2));
    long l=0;
    long u=k;
    for (i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if (k>0)
        {
            long long *p=upper_bound(d,d+l,a[i]);
            long long j=p-d;
            long long gub=l-j;
            if (k>=gub)
            {
                k-=gub;
                d[j]=a[i];
                l=j+1;
            }
            else
            {
                j+=gub-k;
                k=0;
                d[j]=a[i];
                l=j+1;
            }
            //cout << j << "\n";
        }
        else
        {
            d[l++]=a[i];
        }
    }
    for (i=0;i<n-u;i++)
    {
        printf("%lld ",d[i]);
    }
    return 0;
}