#include <cstdlib>
#include <iostream>
#include <cstdio>

using namespace std;

struct put
{
 	   int x,y,a;
};

const int N = 20005, M = 200005;
put putevi[M];
bool moze[N];

bool put_lt(put a, put b)
{
 	 if(a.x == b.x)
 	 {
	  		if(a.y == b.y) return a.a < b.a;
	  		return a.y < b.y;
	 }
	 return a.x < b.x;
}

int main(int argc, char *argv[])
{
 	freopen("asfalt.in","r",stdin);
 	freopen("asfalt.out","w",stdout);
    int n,m;
    scanf("%i %i",&n,&m);
    for(int i = 0; i < n; i++) moze[i] = true;
    int r = n;
    for(int i = 0; i < m; i++)
    {
            int x,y,a;
            scanf("%i %i %i",&putevi[i].x,&putevi[i].y,&putevi[i].a);
            putevi[i].x--; putevi[i].y--;
            /*if(!a)
            {
			 	  if(moze[x]) r--;
			 	  if(moze[y]) r--;
			 	  moze[x] = moze[y] = false;
 	  		}*/
    }
    sort(putevi,putevi + m, put_lt);
//    printf("!");
    putevi[m].x = -1; // filler
    for(int i = 0; i < m; i++)
    {
	 		if(putevi[i].x != putevi[i+1].x || putevi[i].y != putevi[i+1].y)
	 					   if(!putevi[i].a)
   				   		   {
						   				   if(moze[putevi[i].x]) r--;
			 	  						   if(moze[putevi[i].y]) r--;
			 	  						   moze[putevi[i].x] = moze[putevi[i].y] = false;
   				   		   }
	}
    printf("%i\n",r);
    for(int i = 0; i < n; i++) if(moze[i]) printf("%i ",i + 1);
    printf("\n");
    fclose(stdin);
    fclose(stdout);
    return EXIT_SUCCESS;
}
