#include<bits/stdc++.h>

using namespace std;

int n,a;
map<int,vector<int> > br;
int niz[500010];
vector<int> res;

int nadji(int index, int i)
{
    int levi=0;
    int desni=br[i].size()-1;
    while(levi<desni)
    {
        int sr=(levi+desni)/2;
        if(br[i][sr]==index)
            return br[i][sr];
        if(br[i][sr]<index)
            levi=sr+1;
        else
            desni=sr;
    }
    return br[i][levi];
}

bool resi(int index,int prosli, int k)
{
    if(n-index<=k)
        return true;
    if(k==0)
    {
        for(int i=index;i<n;i++)
            res.push_back(niz[i]);
        return true;
    }
    map<int,vector<int> >::iterator it;
    for(it=br.begin();it!=br.end();it++)
    {
        if(!br[it->first].empty())
        {
            int ind=nadji(index, it->first);
            if(ind-prosli<=k && ind>=index)
            {
                //cout<<"*OK "<<i<<" "<<endl;
                res.push_back(it->first);
                return resi(ind+1,ind+1,k-(ind-prosli));
            }
        }
    }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>a;

    for(int i=0;i<n;i++)
        cin>>niz[i];

    for(int i=0;i<n;i++)
        br[niz[i]].push_back(i);

    /*for(int i=0;i<10;i++)
    {
        cout<<i<<"  ";
        for(int j=0;j<br[i].size();j++)
            cout<<br[i][j]<<" ";
        cout<<endl;
    }*/

   //cout<<nadji(0,3);
    bool ok=resi(0,0,a);

    for(int i=0;i<res.size();i++)
        cout<<res[i]<<" ";

    return 0;
}