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

        }
    }
}