#include <cstdio>
#include <vector>
#define maxN 20100
#define maxM 200200

using namespace std;

vector <int> edges[maxN], no[maxN];
bool mark[maxN];

FILE *fin = fopen("asfalt.in", "r"), *fout = fopen("asfalt.out", "w");

int main(){
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 0; i < m; i++){
        int a, b, c;
        fscanf(fin, "%d%d%d", &a, &b, &c);
        if (c){
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        else {
            no[a].push_back(b);
            no[b].push_back(a);
        }
    }

    for (int i = 1; i <= n; i++) mark[i] = true;

    for (int i = 1; i <= n; i++){
        for (int j = 0; j < no[i].size(); j++){
            mark[ no[i][j] ] = false;
        }
    }

    int sol = 0;
    for (int i = 1; i <= n; i++) sol += mark[i];

    fprintf(fout, "%d\n", sol);
    for (int i = 1; i <= n; i++){
        if (mark[i]) fprintf(fout, "%d ", i);
    }

    return 0;
}
