#include<stdio.h>
using namespace std;

int p[2000005],rr[1000005];
int i,n,k,q,pom;

int main()
{
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&q);
		q=q+n+1;
		if (p[q]==-1) continue;
		p[q]++;
		if (p[q]==k) {p[q]=-1; pom++; rr[pom]=q-n-1;}
	}
	
	printf("%d\n",pom);
	for (i=1;i<=pom;i++)
		if (i!=pom) printf("%d ",rr[i]); else printf("%d",rr[i]);
	
}