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)
        {
            
            var ulazna_linija = Console.ReadLine().Split();
            int n = int.Parse(ulazna_linija[0]);
            int k = int.Parse(ulazna_linija[1]);
            int c=0;
            int l = 0;
            int[,] a = new int[n, n];
            int[,] b = new int[n, n];
            var ulazna_linij = Console.ReadLine().Split();
            for (int i = 0;i< n;i++)
                a[0, i] = int.Parse(ulazna_linij[i]);
           
            for(int i=0;i<n;i++){
                c = 0;
            for (int m = i; m < n; m++)
            {
                if (a[0, i] == a[0, m])
                    c++;
                if (c == k)
                {
                    b[0, l] = a[0,i];
                    a[0, m] = -1731;
                    l++;
                    c = 0;
                   
                }
            }
        }
            
            Console.WriteLine(l);
            for (int i = 0; i < l; i++)
            {
                if (i != l - 1)
                {
                    Console.Write(b[0, i]);
                    Console.Write(" ");

                }
                else
                    Console.WriteLine(b[0, i]);
            }
        }
    }
}