#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <vector>
#include <stack>
#include <bitset>
#include <map>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n,k,b,rez,a[1000005];
vector <int>v;
int main(){
cin>>n>>k;
while(n--){
    scanf("%d",&b);
    a[500000+b]++;
    if(a[500000+b]>=k){rez++;a[500000+b]=-2e9;v.push_back(b);}
}
cout<<rez<<endl;
for(int i=0;i<v.size();i++){
    printf("%d ",v[i]);
}
cout<<endl;

return 0;
}