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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ulaz = Console.ReadLine().Split();
            Int64 n = Int64.Parse(ulaz[0]);
            Int64 k = Int64.Parse(ulaz[1]);
            Int64[] a = new Int64[n];
            Int64[] b = new Int64[n];
            Int64 brk = 0;
            var ulaz1 = Console.ReadLine().Split();
            for (int i = 0; i < n; i++) 
            {
                a[i]=Int64.Parse(ulaz1[i]);
            }
            for (Int64 i = -n; i <= n; i++) 
            {

                Int64 br = 0;
                for (int j = 0; j < n; j++) 
                {
                    if (a[j] == i)
                        br++;
                    if (br == k)
                    {
                        b[brk] = a[j];
                        br = 0;
                        brk++;

                    }

                }

            }
            Console.WriteLine(brk);
            for (int i = 0; i < brk; i++) 
            {
                Console.Write(b[i] + " ");
            }
        }
    }
}