import java.util.Scanner;

public class takmicenje {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N=0;
        do {
        	N=sc.nextInt();
        } while(N<1);
		int K=1000001;
		do {
			K=sc.nextInt();
		} while(K>1000000);
		int n=0;
		int m=0;
		int r=0;
		int q=0;
		int[]a=new int[N];
		
		for(int i=0;i<=(N-1);i++) {
			a[i]=sc.nextInt();
			if((a[i]>N) || (a[i]<-N)) {
				i=i-1;
			}
		}
		for(int l=a.length-1; l>0; l--) {
			for(int j=0; j<l; j++) {
				if(a[j]>a[j+1]) {
					int t=a[j];
					a[j]=a[j+1];
					a[j+1]=t;
				}
			}
		}
		while(m<=a.length-1) {
			for(int b=0; b<=a.length-1;b++) {
				if(a[m]==a[b]) {
					n=n+1;
				}
			}
			if (n>=K){
				r=r+1;
			}
			m+=n;
			n=0;	
		}
		System.out.println(r);
		m=0;
		int []c=new int[r];
		while(m<=a.length-1) {
			for(int b=0; b<=a.length-1;b++) {
				if(a[m]==a[b]) {
					n=n+1;
				}
			}
			if (n>=K){
			c[q]=a[m];
			System.out.print(c[q]);
			System.out.print(" ");
			q++;
			}	
			m+=n;
			n=0;	
		}
	}

}