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

namespace Pikado
{
    class Program
    {
        static void Main(string[] args)
        {
            string poc = Console.ReadLine();
            string[] prvalinija = poc.Split(' ');
            int N = int.Parse(prvalinija[0]);
            int K = int.Parse(prvalinija[1]);
            poc = Console.ReadLine();
            string[] drugalinija = poc.Split(' ');
            int[] a = new int[N];
            int[] b = new int[N];
            int g = 0;
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(drugalinija[i]);
            }
            int temp;
            for (int i = 0; i < N - 1; i++)
            {
                temp = 1;
                for (int j = i + 1; j < N; j++)
                {
                    if (a[i] == a[j])
                    {
                        temp++;
                        if (temp >= K)
                        {
                            b[g] = a[i];
                            g++;
                            break;
                        }
                    }
                }
            }
            for (int i = 0; i < g - 1; i++)
            {
                for (int j = i + 1; j < g; j++)
                {
                    if(b[i] == b[j])
                    {
                        b[j] = b[g - 1];
                        g--;
                    }
                }
            }


            Console.WriteLine(g.ToString());
            for (int i = 0; i < g; i++)
            {

                Console.Write(b[i].ToString() + " ");
            }
            Console.ReadLine();
        }
    }
}