#include<bits/stdc++.h>

using namespace std;

int n,a;
map<int,vector<int> > br;
int niz[500010];
int res[500010];
int indexres=0;
set<int> skup;
set<int>::iterator it2;
map<int,vector<int> >::iterator it;

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 k)
{
    if(n-index<=k)
        return true;
    if(k==0)
    {
        for(int i=index;i<n;i++)
            res[indexres++]=niz[i];
        return true;
    }

    skup.clear();
    for(int i=index;i<=index+k;i++)
        skup.insert(niz[i]);

    for(it2=skup.begin();it2!=skup.end();it2++)
    {
        if(!br[*it2].empty())
        {
            int ind=nadji(index, *it2);
            if(ind-index<=k && ind>=index)
            {
                //cout<<"*OK "<<i<<" "<<endl;
                res[indexres++]=*it2;
                return resi(ind+1,k-(ind-index));
            }
        }
    }

}

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,a);

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

    return 0;
}