#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
    int k, n, br = 0, brElem = 0;

    cin >> n >> k;

    int a[n], b[n];

    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a, a+n);

    for(int i = 0; i < n; i++)
    {
        if(i == 0)
        {
            br++;
        }
        else if(a[i-1] == a[i])
        {
            br++;
        }
        else if(a[i-1] != a[i] && br >= k)
        {
            b[brElem] = a[i-1];
            brElem++;
            br=1;
        }
        else
        {
            br = 1;
        }

    }

    if(br >= k)
    {
        b[brElem] = a[n-1];
        brElem++;
        br=1;
    }
    cout << brElem << endl;
    for(int i = 0; i < brElem; i++)
    {
        cout << b[i] << " ";
    }


    return 0;
}