#include <bits/stdc++.h>
using namespace std;
const int mint=1000000;
int a[2*mint+1]={0};
bool b[2*mint+1]={false};
int main()
{
	long long n,k;
	cin>>n>>k;
	long long br=0;
	long long inp;
	vector <int> losi;
	for(long long i=0;i<n;i++)
	{
		cin>>inp;
		a[inp+n]++;
		if(a[inp+n]>=k && !b[inp+n])
		{
			losi.push_back(inp);
			b[inp+n]=true;
			br++;
		}
	}
	cout<<br<<endl;
	for(long long j=0;j<losi.size();j++) cout<<losi[j]<<" ";
	cout<<endl;
	return 0;
}