#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
int n, m;
struct node
{
int pos;
int val;
bool operator<(const node& x)const { return x.val < val; }
};
priority_queue<node>q;
int main()
{
cin >> n >> m;
node no;
int flag = 0;
for (int i = 1;i <= n;i++)
{
cin >> no.val;
flag++;
if (i == 1)
{
cout << 0 << endl;
}
else
{
if (i - m > 0)
{
while (q.top().pos < i - m)
{
q.pop();
}
}
cout << q.top().val << endl;
}
no.pos = i;
q.push(no);
}
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int n, m;
struct node
{
int pos;
int val;
};
int main()
{
cin >> n >> m;
vector<node>v;
node no;
for (int i = 1;i <= n;i++)
{
cin >> no.val;
no.pos = i;
if (i == 1)
{
cout << 0 << endl;
}
else
{
vector<node>::iterator pos = v.end();
pos--;
int flag = (*pos).val;
while (1)
{
if (v.size()==1)
{
break;
}
vector<node>::iterator pos1 = v.end();
pos1--;
pos1--;
if ((*pos1).val >flag)
{
//cout << (*pos).val << " " << no.val << endl;
v.erase(pos1);
}
else
{
break;
}
}
if (i - m > 0)
{
while ((*v.begin()).pos < i - m)
{
v.erase(v.begin());
}
}
cout << (*v.begin()).val << endl;
}
v.push_back(no);
}
return 0;
}