#include <cstdlib>
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char *argv[])
{
    FILE *in, *out;
    in=fopen("asfalt.in","r");
    out=fopen("asfalt.out","w");
    int n,m;
    fscanf(in,"%d",&n);
    fscanf(in,"%d",&m);
    int towns[n];
    for(int i=0; i<n; i++) towns[i]=0;
    for(int i=0; i<m; i++)
        {
            int a,b,c;
            fscanf(in,"%d",&a);
            a--;
            fscanf(in,"%d",&b);
            b--;
            fscanf(in,"%d",&c);
            towns[a]+=1-c;
            towns[b]+=1-c;
        }
    int count=0;
    for(int i=0; i<n; i++)
        if(towns[i]==0) count++;
    fprintf(out,"%d\n",count);
    for(int i=0; i<n; i++)
        if(towns[i]==0) fprintf(out,"%d ",i+1);
    fclose(in);
    fclose(out);
    return 0;
}

/*
4 4
1 2 1
2 3 1
3 4 1
4 1 0
*/
