#include <bits/stdc++.h>
#define maxN 500005

using namespace std;

vector <int> v,u,w[maxN],s;
int n,i,j,t,k,a[maxN],sl[maxN];

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    for(i=0;i<v.size()-1;i++){
        if(v[i]!=v[i+1]) u.push_back(v[i]);
    }
    u.push_back(v.back());
    v.clear();
    for(i=0;i<n;i++){
        int tmp=lower_bound(u.begin(),u.end(),a[i])-u.begin();
        a[i]=tmp;
        w[tmp].push_back(i);
    }
    if(n<=200005){
        for(i=0;i<n;i++){
        for(j=0;j<u.size();j++){
            t=lower_bound(w[j].begin(),w[j].end(),i)-w[j].begin();
            if(t==w[j].size()) {t=-1; continue;}
            t=w[j][t];
            if(a[t]==j && n-t-1>=n-k-v.size()-1) {v.push_back(j); break;}
        }
        if(t==-1) break;
        i=t;
    }
    }
    else{
        for(i=n-1;i>=0;i--){
            sl[i]=n;
            while(s.size() && a[s.back()]>=a[i]) s.pop_back();
            if(s.size()) sl[i]=s.back();
            s.push_back(i);
        }
        for(i=0;i<n;i++){
        t=sl[i];
        if(n-t<n-k-v.size()) {v.push_back(a[i]); continue;}
        i=t-1;
    }
    }
    for(i=0;i<v.size();i++) cout<<u[v[i]]<<" ";
    return 0;
}