#include <iostream>
#include <list>

using namespace std;

struct grad
{
    list<pair<int, bool> > p;
    int n;
};

int n, m;
grad g[20005];
int res[20005];
int k;

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