#include <bits/stdc++.h>
#include <climits>

#include <math.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;

    vector<int>zamenjena(2*n+1);
    int b,z=0;
    int hits[2*n+1];
    memset(hits,0,sizeof(hits));
    for(int i=0;i<n;i++){
       cin>>b;
       hits[b+n]++;
       if(hits[b+n]==k){
        zamenjena[z]=b;
        z++;
        hits[b+n]=INT_MIN;
       }
    }
    cout<<z<<endl;
    for(int i=0;i<z;i++){
        cout<<zamenjena[i]<<" ";
    }

    return 0;
}