#include "iostream"
using namespace std;

struct cuvanje{
	unsigned int kolicina;
	unsigned int velicina;
	bool da;
};

int main(){
	int N, K;
	cin >> N;
	cin >> K;
	struct cuvanje A[2*N+1];
	int res[2*N+1];
	int n=0;
	int resn=0;
	
	int kolicina=0;
	
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		
		A[n].velicina = N+1;
		
		int p = n;
		
		bool da = true;
		for(int i=0;i<n;i++)
			if(A[i].velicina==a){
			da = false;
			p=i;
			break;
		}
		
		if(da){
			A[n].da = false;
			A[n].velicina=a;
			A[n].kolicina=1;
			n++;
		}
		else{
			A[p].kolicina++;
			if(!A[p].da && A[p].kolicina>=K){
				A[p].da = true;
				res[resn]=A[p].velicina;
				kolicina++;
				resn++;
			}
		}
	}
		
	cout << kolicina << endl;
	for(int i=0;i<resn;i++)
		cout << res[i] << " ";
	
}