#include<stdio.h>

FILE *fin,*fout;

int n,m,a,b,d,br,i,p[25000];

int main()
{
 fin=fopen("asfalt.in","r");
 fout=fopen("asfalt.out","w");
 fscanf(fin,"%d%d",&n,&m);
 br=n;
 for(i=0;i<m;i++)
 {
  fscanf(fin,"%d%d%d",&a,&b,&d);
  if(d==0)
  {
   if(p[a]!=1)
   {
    p[a]=1;
    br--;
   }
   if(p[b]!=1)
   {
    p[b]=1;
    br--;
   }
  }
 }
 fprintf(fout,"%d\n",br);
 for(i=1;i<=n;i++)
 {
  if(p[i]!=1)
  {
   fprintf(fout,"%d ",i);
  }
 }
 return 0;
}
