#include <iostream>

using namespace std;

int main()
{
    long long n,k,l,m=0,br=0,q;
    cin>>n>>k;
    long long a[n];
    long long b[100000];
    for (long long i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(long long i=0;i<n-1;i++)
    {
        l=i;
        for (long long j=i+1;j<n;j++)
        {
            if(a[j]>a[l])
                l=j;
        }
    swap(a[l],a[i]);
    }
    for (long long i=0;i<n-1;i++)
    {
        if (a[i]==a[i+1])
        {
            b[br]=a[i];
            br=br+1;
            m=m+1;
        }
    }
    for (long long i=0;i<br;i++)
    {
        if (b[i]==b[i+1])
        {
            m=m-1;
        }
    }
    cout<<m<<endl;
    for (long long i=0;i<br;i++)
    {
        if (b[i]!=b[i+1])
        {
            cout<<b[i]<<" ";
        }
    }
    return 0;
}