#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define PB push_back
#define SZ size()
#define CLR clear()

FILE *ff = fopen("asfalt.in", "r");
FILE *gg = fopen("asfalt.out", "w");

const int MaxN = 20005;

int n, m, x[MaxN];
vector <int> a[MaxN], b[MaxN], w[MaxN];

int main(){
    fscanf(ff, "%d%d", &n, &m);

    for (int i = 1; i <= n; i++) a[i].CLR, b[i].CLR;

    for (int i = 1; i <= m; i++){
        int x, y, z;
        fscanf(ff, "%d%d%d", &x, &y, &z);
        a[x].PB(y); w[x].PB(z);
        a[y].PB(x); w[y].PB(z);
        if (z == 1) b[x].PB(y), b[y].PB(x);
    }

    if (n <= 3){
        fprintf(gg, "%d\n", n);
        fprintf(gg, "1");
        for (int i = 2; i <= n; i++) fprintf(gg, " %d", i);
        fprintf(gg, "\n");
    }

    int sol = 0;
    for (int i = 1; i <= n; i++)
        if (b[i].SZ > 1){
            sol++; x[sol] = i;
        }

    fprintf(gg, "%d\n", sol);
    fprintf(gg, "%d", x[1]);
    for (int i = 2; i <= sol; i++) fprintf(gg, " %d", x[i]); fprintf(gg, "\n");

    fclose(ff); fclose(gg);
    return 0;
}
