#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector <int> v;
    int n,k,b,rez=0;
    cin >> n >> k;
    int a[2*n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> b;
        a[b+n]++;
        if(a[b+n]>=k)
        {
            v.push_back(b);
            a[b+n]=-n;
            rez++;
        }
    }
    cout << rez << "\n";
    for(int i=0;i<v.size();i++)
    {
        cout << v[i] << " ";
    }
    return 0;
}