#include <iostream>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int* p = new int[n];
    int br=0, *pogodak = new int[n];
    for (int i = 0; i < n-br; i++)
    {
        cin >> p[i];
        pogodak[i] = 1;
        for(int j = i-1; j >=0; j--)
        { 
            if (p[i] == p[j])
            {
                pogodak[j]++;
                
                br++;
                
                p[i] = p[n - br - 1];
                i--;
            }
        }
    }
    cout << br << endl;
    for (int i = 0; i < n - br; i++)
        if(pogodak[i] >= k)
            cout << p[i] << " ";
}