#include <bits/stdc++.h>
using namespace std;
int n, k, a;
int uses[1000005];
int out[1000005], nOut;
int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a);
        ++uses[a];
        if (uses[a] >= k)
        {
            out[nOut] = a;
            ++nOut;
            uses[a] = INT_MIN;
        }
    }
    printf("%d\n", nOut);
    for (int i = 0; i < nOut; ++i)
    {
        printf("%d ", out[i]);
    }
    return 0;
}