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

using namespace std;

vector <int> v,u,w[maxN];
int n,i,j,t,k,a[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);
    }
    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;
    }
    for(i=0;i<v.size();i++) cout<<u[v[i]]<<" ";
    return 0;
}