#include <iostream>
#include <vector>
#include <algorithm>

//#define DEBUG

using namespace std;

int main()
{
    int n, k;
    int br = 0;
    cin >> n >> k;
    vector<int> pikado(n);
    vector<int> res;
    for(int i = 0; i < n; ++i){
        cin >> pikado[i];
    }
#ifdef DEBUG
    cout << "--------DEBUG---------\n";
#endif // DEBUG
    sort(pikado.begin(), pikado.end());
#ifdef DEBUG
    for(int i = 0; i < n; ++i){
        cout << pikado[i] << " ";
    }
    cout << endl;
#endif // DEBUG
    for(int i = 1; i < n; ++i){
        if(pikado[i] == pikado[i-1]){
            ++br;
#ifdef DEBUG
            cout << pikado[i] << " == " << pikado[i-1] << endl;
            cout << "br = " << br << endl;
#endif // DEBUG
        }
        else{
#ifdef DEBUG
            cout << pikado[i] << " != " << pikado[i-1] << endl;
#endif // DEBUG
            if(br >= k-1){
#ifdef DEBUG
                cout << "br = " << br << ", k = " << k << endl;
                cout << "res.push_back(" << pikado[i-1] << ")\n";
#endif // DEBUG
                res.push_back(pikado[i-1]);
            }
            br = 0;
        }
    }
    int s = res.size();
    if(br >= k-1){
        res.push_back(pikado[n-1]);
        ++s;
    }
#ifdef DEBUG
    cout << "--------RES---------\n";
#endif // DEBUG
    cout << s << endl;
    for(int i = 0; i < s; ++i){
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}