#include <bits/stdc++.h>
using namespace std;

int main(){
   int n,k;
   map<int,int> m;
   scanf("%d %d",&n,&k);
   vector<int> rez;
   for(int i=0;i<n;i++){
     int x;
     scanf("%d",&x);
     if(m.find(x)==m.end())m[x]=1;
     else m[x]++;
     if(m[x]>=k){
       rez.push_back(x);
        m[x]=-n;
     }
   }
   printf("%d\n",rez.size());
   for(int i=0;i<rez.size();i++)printf("%d ",rez[i]);
    return 0;
}