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

namespace Zadatak_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            int K;
            int brojac = 1;
            int temp;
            int j = 0;

            string[] unos = new string[2];

            unos = Console.ReadLine().Split(' ');

            N = Convert.ToInt32(unos[0]);
            K = Convert.ToInt32(unos[1]);

            unos = new string[N];

            unos = Console.ReadLine().Split(' ');

            int[] niz = new int[N];
            int[] niz1 = new int[N];

            for (int i = 0; i < N;i++)
            {
                niz[i] = Convert.ToInt32(unos[i]);
            }

            Array.Sort(niz);

            temp = niz[0];

            for (int i = 1; i < N; i++)
            {
                if (niz[i] == temp)
                {
                    brojac++;
                }
                else
                {
                    if (brojac >= K)
                    {
                        niz1[j] = temp;
                        j++;
                    }

                    brojac = 1;
                    temp = niz[i];
                }
            }

            if (brojac >= K)
            {
                niz1[j] = temp;
                j++;
            }

            Console.WriteLine(j);

            for (int i = 0; i < j - 1; i++)
            {
                Console.Write(niz1[i] + " ");
            }
            Console.Write(niz1[j - 1]);
        }
    }
}