//package pikado;

import java.util.Scanner;

public class Pikado {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt(), k = in.nextInt();
        
        int[] niz = new int[n];
        
        for (int i = 0; i < n; i++) {
            niz[i]=in.nextInt();
        }
        
        int[] res = new int[n];
        
        int rob = 0;
        
        for (int i = 0; i < n; i++) {
                int num = niz[i];
                int br = 0;
                for (int j = i; j < n; j++) {
                    if(num == niz[j]){
                        niz[j] = 0;
                        br++;
                    }
                }
                if(br>=k){
                    res[rob] = num;
                    rob++;
                }
               
        }
        int len = 1;
        for(int i = 1; i<rob;i++){
            if(res[i]!=res[i-1]){
                len++;
            }
        }
            System.out.print(len);
            System.out.print(res[0] + " ");
        for (int i = 1; i < rob; i++) {
            if(res[i]==res[i-1]){
                continue;
            }else{
                System.out.print(res[i] + " ");
            }
        }
        
        
    }
    
}