#include <stdio.h>
bool mark[30000];
int n,m,w1,w2,w3,i,res;
FILE *f;
FILE *g;
int main()
{
    f=fopen("asfalt.in","r");
    g=fopen("asfalt.out","w");
    fscanf(f,"%d%d",&n,&m);
    for (i=1;i<=n;i++) mark[i]=1;
    for (i=0;i<m;i++)
    { fscanf(f,"%d%d%d",&w1,&w2,&w3); if (w3==0) {mark[w1]=false;mark[w2]=false;}}
    res=0;
    for (i=1;i<=n;i++) if (mark[i]) res++;
    fprintf(g,"%d\n",res);
    for (i=1;i<=n;i++) if (mark[i]) {if (i<n) fprintf(g,"%d ",i); else fprintf(g,"%d\n",i);}
    fclose(f); fclose(g);
    return 0;
}
