#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> pq;
int* a;
int* d;
int main()
{
    int n, k;
    cin >> n >> k;
    a = new int[n];
    d = new int[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        while(!pq.empty() && a[pq.top()] > a[i])
        {
            d[pq.top()] = i - pq.top();
            pq.pop();
        }
        pq.push(i);
    }
    while(!pq.empty())
    {
        d[pq.top()] = INT_MAX;
        pq.pop();
    }
    for(int i = 0; i < n && k > 0; i++)
        if(k >= d[i])
        {
            a[i] = -1;
            k--;
        }
    for(int i = n - 1; k > 0; i--) a[i] = -1;
    for(int i = 0; i < n; i++)
        if(a[i] != -1)
            cout << a[i] << " ";
}