#include <iostream>

using namespace std;

int main()
{
    long long int a,N,K,b,c,e=0,f=0,g=0;
    cin >> N;
    cin >> K;
    long long int A[N],B[N];

    for (a=0;a<N;a++){
        cin >> A[a];
    }

     for (a = 0; a < N; ++a)
        {

            for (b = a + 1; b < N; ++b)
            {

                if (A[a] > A[b])
                {

                    c =  A[a];
                    A[a] = A[b];
                    A[b] = c;

                }

            }

        }
if (N<1 || K<1)
    return 0;
if(N<K)
{cout << "0";
return 0;
}
c=0;


if(K==1){
for (a=0;a<N;a++)
{

if(A[a]==A[a+1])
 continue;
else B[f]=A[a];
f++;
e++;

}
cout << e << endl;
for(a=0;a<f;a++)
cout << B[a] << " ";

return 0;
}



for(;c<N;c+=a-c+1)
{


for (a=c;a<K-1+c;a++){
        b=a+1;
if(B[f-1]==A[a])
goto kraj;
        if(A[a]==A[b]);
            else
                goto kraj;

    }

    e++;
    B[f]=A[a];
    f++;
    kraj:
continue;
}

cout << e << endl;
for (a=0;a<f;a++)
cout << B[a] << " ";








    return 0;
}