#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define loop(a,b,c) for(ll i=a;i<=b;i+=c)
#define intarr(arr,n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i]
#define inparr(arr,n) for(ll i=0;i<n;i++)cin>>arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define newline cout<<endl
#define ump unordered_map<ll,ll>
#define vec vector<ll>
#define mkp make_pair
#define disp(var1,var2) cout<<var1<<" "<<var2<<endl;
#define all(v) v.begin(),v.end()
#define cout(var) cout<<var<<endl
#define p 998244353
#define teensort(a,r,g,b) a[0]=r;a[1]=g;a[2]=b;sort(a,a+3);
ll a[200005];
void AcDegaYe()
{
ll n,k;
cin>>n>>k;
k=min(k,n);
for(ll i=0;i<n;i++)
cin>>a[i];
list<ll> v;
ump h;
for(ll i=0;i<n;i++)
{
if(v.size()<k)
{
if(h.count(a[i])==0)
{
v.push_front(a[i]);
h[a[i]]=1;
}
else
continue;
}
else
{
if(h.count(a[i])==1)
{
continue;
}
else
{
h.erase(v.back());
v.pop_back();
v.push_front(a[i]);
h[a[i]]=1;
}
}
}
cout(v.size());
for(auto it:v)
{
cout<<it<<" ";
}
cout<<endl;
}
int main()
{
fastio
//ll t;
//cin>>t;
ll t=1;
while(t--)
{
AcDegaYe();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7IAojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nIGludAojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgbG9vcChhL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aTxuO2krKykKICAgIHsKICAgICAgICBpZih2LnNpemUoKTxrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoaC5jb3VudChhW2ldKT09MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdi5wdXNoX2Zyb250KGFbaV0pOwogICAgICAgICAgICAgICAgaFthW2ldXT0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZihoLmNvdW50KGFbaV0pPT0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGguZXJhc2Uodi5iYWNrKCkpOwogICAgICAgICAgICAgICAgdi5wb3BfYmFjaygpOwogICAgICAgICAgICAgICAgdi5wdXNoX2Zyb250KGFbaV0pOwogICAgICAgICAgICAgICAgaFthW2ldXT0xOwoKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGNvdXQodi5zaXplKCkpOwogICAgZm9yKGF1dG8gaXQ6dikKICAgIHsKICAgICAgICBjb3V0PDxpdDw8IiAiOwogICAgfQogICAgY291dDw8ZW5kbDsKfQoKCmludCBtYWluKCkKeyAgIAogICAgZmFzdGlvCiAgICAvL2xsIHQ7CiAgICAvL2Npbj4+dDsKICAgIGxsIHQ9MTsKICAgIHdoaWxlKHQtLSkKICAgIHsKICAgICAgICBBY0RlZ2FZZSgpOwogICAgfQogICAgY2VyciA8PCAiXG5UaW1lIGVsYXBzZWQ6ICIgPDwgMTAwMCAqIGNsb2NrKCkgLyBDTE9DS1NfUEVSX1NFQyA8PCAibXNcbiI7CiAgICByZXR1cm4gMDsKfQ==