#include <cstdio>
#include <iostream>

using namespace std;

#define maxN 20005

int n, m;
int d[maxN], deg[maxN];

int main () {
    freopen("asfalt.in", "r", stdin);
    freopen("asfalt.out", "w", stdout);
    
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
		int from, to, ok;
		scanf("%d%d%d", &from, &to, &ok);
        if ( ok ) {
        	deg[from]++;
        	deg[to]++;
		}
        else {
        	d[from]++;
        	d[to]++;
		}
	}
	
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if ( d[i] == 0 )
			cnt++;
	printf("%d\n", cnt);
	for (int i = 1; i <= n; i++)
		if ( d[i] == 0 )
			printf("%d ", i);
	printf("\n");

    return 0;    
}
