program project1;

var a:array of int64;
    d:array of int64;
    c:array of int64;
    i,j,x,n,k,db:int64;

begin

read(n,k);
setlength(d,n);
for i:=1 to n do read(d[i]);
setlength(a,(2*n)+1);
setlength(c,1);

db:=0;
j:=1;
for i:=1 to n do
  begin
  x:=d[i];
  a[n+1+x]:=a[n+1+x]+1;
  if (a[n+1+x] = k) then
    begin
    db:=db+1;
    setlength(c,db+1);
    c[j]:=x;
    j:=j+1;
    end;
  end;

writeln(db);
for i:=1 to db do write(c[i],' ');

end.