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

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, K,T,C=0,i,j=0,Z=0,k=0;
            string[] input1;
            string[] input2;
            input1 = new string[2];
            input1 = Console.ReadLine().Split(' ');
            N = Convert.ToInt32(input1[0]);
            K = Convert.ToInt32(input1[1]);
            input2 = new string[N];
            input2 = Console.ReadLine().Split(' ');
            int[] pogodci= new int[N];
            int[] zamena = new int[N];
            for (i = 0; i < N; i++)
            {
                pogodci[i] = Convert.ToInt32(input2[i]);
            }
            i = 0;
            Array.Sort(pogodci);
            while (true) {

                T = pogodci[i];
                while (j<N) {
                    if (T == pogodci[j])
                    {
                        C++;
                    }
                    j++;
                }
                j = 0;
                if (C >= K) {
                    Z++;
                    zamena[k] = T;
                    k++;
                }
                i = i + C;
                C = 0;
                if (i==N)
                {
                    break;
                }
            }
            
            Array.Resize(ref zamena, Z);
            Console.WriteLine("{0}", Z);
            string tost;
            tost = String.Join(" ", zamena.Select(p => p.ToString()).ToArray());
            Console.WriteLine("{0}", tost);
        }
    }
}