#include<stdio.h>
#include<vector>

using namespace std;

vector<int> a[20000];
int n;

int main()
{
      int i,m;
      FILE *f,*g;
      bool b[20000];
      f=fopen("asfalt.in","r");
      g=fopen("asfalt.out","w");  
      fscanf(f,"%d %d",&n,&m);
      for(i=0;i<n;i++) b[i]=true;
      for(i=0;i<m;i++)
      {
                      int _a,_b,_c;
                      fscanf(f,"%d %d %d",&_a,&_b,&_c);_b--;_a--;
                      if(_c==0)
                      {
                              b[_a]=false;
                              b[_b]=false;        
                      }     
      }
      int s=0;
      for(i=0;i<n;i++) if(b[i]) s++;
      fprintf(g,"%d\n",s);
      for(i=0;i<n;i++) if(b[i]) fprintf(g,"%d ",i+1);
      fclose(f);
      fclose(g);
}
