#include <stdio.h>
#include <string.h>

long N, M;

bool nemaAsfalt[20001];
long possible[20001];
size_t pos_cnt=0;

int main(int argc, char *argv[])
{
	memset(nemaAsfalt, 0, 20001);
	
	FILE *fin = fopen("asfalt.in", "r");
	fscanf(fin, "%d %d\n", &N, &M);
	for (long loop_M=0; loop_M<M; loop_M++) {
		long from, to, hasA;
		fscanf(fin, "%d %d %d\n", &from, &to, &hasA);
		if (hasA == 0) {
			nemaAsfalt[from] = true;
			nemaAsfalt[to] = true;
		}
	}
	fclose(fin);
	
	for (long z1=1; z1<=N; z1++) {
		if (!nemaAsfalt[z1]) {
			possible[pos_cnt] = z1;
			pos_cnt++;
		}
	}
	
	FILE *fout = fopen("asfalt.out", "w");
	fprintf(fout, "%d\n", pos_cnt);
	bool notFirst = false;
	for (long p=0; p<pos_cnt; p++) {
		if (notFirst) fprintf(fout, " ");
		else notFirst = true;

		fprintf(fout, "%d", possible[p]);
	}
	fprintf(fout, "\n");
	fclose(fout);
}
