program asfalt;
var n,m,i,s,a,b,c:longint;
  x:array[1..2000]of boolean;
    f,g:text;
begin
  assign(f,'asfalt.in');
  assign(g,'asfalt.out');
  reset(f);
  rewrite(g);
  readln(f,n,m);
  for i:=1 to n do
    x[i]:=true;
  s:=n;
  for i:=1 to m do
    begin
      readln(f,a,b,c);
      if c=0 then
        begin
          if x[a]=true then
            begin
              s:=s-1;
              x[a]:=false;
            end;
          if x[b]=true then
            begin
              s:=s-1;
              x[b]:=false;
            end;
        end;
    end;
  writeln(g,s);
  for i:=1 to n do
    if x[i]=true then write(g,i,' ');
  writeln(g);
  close(f);
  close(g);
end.