#include <iostream>
#include <deque>
#include <math.h>
#include <algorithm>
using namespace std;
const int N = 500007;
int numbers[N];
int bad[N];
deque<int> good;
int main()
{
    ios :: sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    for(int i = 0; i<n; i++)
        cin >> numbers[i];

    int last = numbers[0];
    int last_i = 0;
    good.push_back(numbers[0]);
    int d = 1;
    for(int i=1; i<n; i++)
    {
//        if(numbers[i]<good.back())
//            cout << numbers[i] << ' ' << good.size() << ' ' << k-n+i << endl;
        //int t = (k-n+i);
        while(d> 0 && d>= i-k+1&& numbers[i]<good.back())
        {
            good.pop_back();
            d--;
        }
        good.push_back(numbers[i]);
        d++;
    }
    for(int i=0; i<n-k; i++)
        cout << good[i] << ' ';


    return 0;

}