#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+56;

int n,k;
int cnt[2*N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    vector <int> v;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(cnt[x+n] != -1){
            cnt[x+n]++;
        }
        if(cnt[x+n] >= k){
            cnt[x+n] = -1;
            v.push_back(x);
        }
    }
    cout << v.size() << endl;
    for(auto f : v){
        cout << f << " ";
    }
    cout << endl;
}