#include <iostream>

using namespace std;

int n,k,t,c = 0,out[1000003],in[2000003];

int main()
{


    cin >> n >> k;

    for(int i = 0;i < n;i++){
        cin >> t;

        in[n + t]++;
        if(in[n + t] == k){
            out[c] = t;
            c++;
            in[n + t] = 0;
        }
    }

    cout << c << endl;
    for(int i = 0;i < c;i++){
        cout << out[i] << " ";
    }

    return 0;
}