using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList lis = new ArrayList();
            string[] tokens = Console.ReadLine().Split();
            long N = long.Parse(tokens[0]);
            long K = long.Parse(tokens[1]);
            long[] A = new long[N];
            tokens = Console.ReadLine().Split();
            for (long i = 0; i < N; i++)
            {
                A[i] = long.Parse(tokens[i]);
            }
            Array.Sort(A);
            for (long i = 0; i < N-K; i++)
            {
                if ((A[i]==A[i+K-1]) && !((lis.Contains(A[i])) && (lis.Contains(A[i + K-1]))))
                {
                    lis.Add(A[i]);
                    i = i + K-1;
                }
            }
            Console.WriteLine(lis.Count.ToString());
            for (int i = 0; i < lis.Count; i++)
            {
                Console.Write(lis[i] + " ");
            }
        }
    }
}