#include <cstdio>

int n , k , i , p , A[500010];

int Min(int x , int y)
{
    if (x < y) return x;
    return y;
}

int Poz(int x , int y)
{
    int m = A[x];
    int p = x;
    for (int i = x + 1;i <= y;++i)
    {
        if (A[i] < m)
        {
            m = A[i];
            p = i;
        }
    }
    return p;
}

int main()
{
    scanf("%d%d" , &n , &k);
    for (i = 1;i <= n;++i)
    {
        scanf("%d" , &A[i]);
    }
    i = Poz(1 , Min(k + 1 , n));
    k -= i - 1;
    while (i <= n)
    {
        printf("%d " , A[i]);
        p = Poz(i + 1 , Min(i + k + 1 , n));
        k -= p - i - 1;
        i = p;
    }
    return 0;
}