#include<iostream>
#include<stack>
using namespace std;
int main(){
int n,c,c_=0;
cin>>n>>c;
stack<int> st;
int o;
for(int i=0;i<n;i++){
cin>>o;
if(st.empty()||st.top()>=o){
if(c_>=c){
cout<<o<<' ';
}else{
c_++;
st.push(o);
}
}else{
while(!st.empty()&&st.top()<o){
cout<<st.top()<<' ';
st.pop();
c_--;
}
c_++;
st.push(o);
}
}
while(!st.empty()){
cout<<st.top()<<' ';
st.pop();
}
}
求求了