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

using namespace std;

const int N = 20005;
bool moze[N];

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",&x,&y,&a);
            x--; y--;
            if(!a)
            {
			 	  if(moze[x]) r--;
			 	  if(moze[y]) r--;
			 	  moze[x] = moze[y] = false;
 	  		}
    }
    printf("%i\n",r);
    for(int i = 0; i < n; i++) if(moze[i]) printf("%i ",i + 1);
    printf("\n");
//    system("PAUSE");
    fclose(stdin);
    fclose(stdout);
    return EXIT_SUCCESS;
}
