#include<stdio.h>
#include<stdlib.h>
int comparetor (const void * a, const void * b)
	{
		return ( *(int*)a - *(int*)b );
	}
int main()
{
	int N,K,i,b=1,c=0,j=0;
	scanf("%d",&N);
	scanf("%d",&K);
	int x[N],k[N];
	for (i=0;i<N;i++)
	scanf("%d",&x[i]);
	qsort(x, N, sizeof(int), comparetor);
	for(i=0;i<N;i++)
	{
		if(x[i]==x[i+1]){
			b++;
		}
		if(x[i]!=x[i+1]){
			if(b>=K){
			k[j]=x[i];
			j++;
			c++;
		}
			b=1;
		}
	}
	printf("%d\n",c);
	for(i=0;i<j;i++)
	printf("%d ", k[i]);
	return 0;
}