#include <iostream>
#include <set>
#include <vector>

#define lim 1000000

using namespace std;

int main(){
	
	long long n,k,ca,brp=0,br=0;
	vector<int>a;
	set<int>b;
	vector<int>v;
	cin>>n>>k;
	int carry;
	for(int i=0;i<n;i++){
		cin>>carry;
		a.push_back(carry);
		b.insert(a[i]);
	}
	set<int>::iterator it=b.begin();
    for(;it!=b.end();it++){
    	ca=*it;
    	for(int i=0;i<n;i++){
    		if(a[i]==ca){
    			brp++;
    		}
    		if(brp==k){
    			v.push_back(ca);
    			br++;
    			break;
    		}
    	}
    	brp=0;
    }
    cout<<br<<endl;
    for(int i=0;i<br;i++){
    	cout<<v[i]<<" ";
    }
    
    
    
}