#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

int n;
int m;
int cnt[20005];

int main() {
    freopen("asfalt.in", "r", stdin);
    freopen("asfalt.out", "w", stdout);
    memset(cnt, 0, sizeof(cnt));
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        if (c == 0) {
            ++cnt[a];
            ++cnt[b];
        }
    }
    int res = 0;
    for (int i = 1; i <= n; ++i)
        if (!cnt[i])
            ++res;
    printf("%d\n", res);
    for (int i = 1; i <= n; ++i)
        if (!cnt[i])
            printf("%d ", i);
    return 0;
}
