#include <iostream>
#include <vector>
using namespace std;

int main(){

    unsigned int n,k;
    cin >> n >> k;

    vector<int> arr(2*n+1,0);

    int j;
    unsigned int br = 0;
    vector<int> index;

    
    for(int i = 0;i < n; i++){
        cin >> j;
        if(arr[n+j] != -1){
            arr[n+j]++;
            if(arr[n+j] >= k){
                br++;
                index.push_back(j);
                arr[n+j] = -1;
            }
        }
    }

    cout << br << endl;
   for (auto i = index.begin(); i != index.end(); ++i)
        cout << *i << " ";


    return 0;
}