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

long N, M;

char connct[20001][20001];
long possible[20001];
size_t pos_cnt=0;

int main(int argc, char *argv[])
{
	memset(connct, 0, 20001*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);
		connct[from][to] = hasA+1;
		connct[to][from] = hasA+1;
	}
	fclose(fin);
	
	for (long z1=1; z1<=N; z1++) {
		bool isPossible = true;
		for (long z2=1; z2<=N; z2++) {
			if (connct[z1][z2] == 1) {
				isPossible = false;
				break;
			}
		}
		if (isPossible) {
			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);
}
