#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#define maxn 10001
using namespace std;
vector<int> G[maxn];
int BeFok[maxn];
int van_szulo[maxn],van_gyerek[maxn],szulo[maxn][2];
int n;
// mintafeladat megoldását használva
// él: gyerek felé mutat
void Beolvas(){
int m,p,q1,q2;
cin>>n>>m;
for(int i=1;i<=n;i++){BeFok[i]=0;van_szulo[i]=0;van_gyerek[i]=0;}
for (int i=0;i<m;i++){
cin>>p>>q1>>q2;
G[q1].push_back(p);
G[q2].push_back(p);
BeFok[p]+=2;
szulo[p][0]=q1;
szulo[p][1]=q2;
van_szulo[p]=1;
van_gyerek[q1]=1;
van_gyerek[q2]=1;
}
}
int main(){
Beolvas();
vector<int> nev[n];
int cnt,d,i,j,p,q,si,si2,size,szulo1,szulo2,melyseg=0,sol[maxn];
unsigned int bit[32],**os,ans[maxn+1];
// topologikus sorrend megkeresése
for (int p=1;p<=n;p++)
if(BeFok[p]==0)
nev[0].push_back(p);
while(nev[melyseg].size()>0){
si=nev[melyseg].size();
for(i=0;i<si;i++){
p=nev[melyseg][i];
si2=G[p].size();
for(j=0;j<si2;j++){
q=G[p][j];
BeFok[q]--;
if(BeFok[q]==0)
nev[melyseg+1].push_back(q);
}
}
melyseg++;
}
bit[0]=1;for(i=1;i<32;i++)bit[i]=2*bit[i-1];
si=(n+32)/32;
os=(unsigned int**)malloc((n+1)*sizeof(unsigned int*));
for(i=0;i<=n;i++)os[i]=(unsigned int*)malloc(si*sizeof(unsigned int));
// Mindenkinek megkeresem az őseit, topologikus sorrendben veszem a pontokat, így egy pontra ez csak O(n) időbe kerül
// igazából máshogy is O(n) idő lenne, de pont a top. sorrend miatt a szülők ősei ismertek, így lehet "éselni", azaz gyorsítani
// az egész algoritmust!
for(d=0;d<melyseg;d++){
size=nev[d].size();
for(i=0;i<size;i++){
p=nev[d][i];
if(!van_szulo[p]){for(j=0;j<si;j++)os[p][j]=0;}
else{
szulo1=szulo[p][0];
szulo2=szulo[p][1];
for(j=0;j<si;j++)os[p][j]=os[szulo1][j]|os[szulo2][j];
os[p][szulo1>>5]|=bit[szulo1&31];
os[p][szulo2>>5]|=bit[szulo2&31];
}
}
}
for(j=0;j<si;j++)ans[j]=0xffffffff;
for(d=0;d<melyseg;d++){
size=nev[d].size();
for(i=0;i<size;i++){
p=nev[d][i];
if(!van_gyerek[p])
{for(j=0;j<si;j++)ans[j]&=os[p][j];}// nincs gyereke p-nek
}
}
cnt=0;
for(i=1;i<=n;i++)
if(ans[i>>5]&bit[i&31])sol[cnt++]=i;// az "i" közös ős lesz
cout<<cnt<<endl;
if(cnt){
for(i=0;i<cnt;i++){cout<<sol[i];if(i<cnt-1)cout<<" ";}
cout<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2RlZmluZSBtYXhuIDEwMDAxCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnZlY3RvcjxpbnQ+IEdbbWF4bl07CmludCBCZUZva1ttYXhuXTsKaW50IHZhbl9zenVsb1ttYXhuXSx2YW5fZ3llcmVrW21heG5dLHN6dWxvW21heG5dWzJdOwppbnQgbjsKCi8vIG1pbnRhZmVsYWRhdCBtZWdvbGTDoXPDoXQgaGFzem7DoWx2YQovLyDDqWw6IGd5ZXJlayBmZWzDqSBtdXRhdAp2b2lkIEJlb2x2YXMoKXsKICAgaW50IG0scCxxMSxxMjsKICAgY2luPj5uPj5tOwogICBmb3IoaW50IGk9MTtpPD1uO2krKyl7QmVGb2tbaV09MDt2YW5fc3p1bG9baV09MDt2YW5fZ3llcmVrW2ldPTA7fQogICBmb3IgKGludCBpPTA7aTxtO2krKyl7CiAgICAgIGNpbj4+cD4+cTE+PnEyOwogICAgICBHW3ExXS5wdXNoX2JhY2socCk7CiAgICAgIEdbcTJdLnB1c2hfYmFjayhwKTsKICAgICAgQmVGb2tbcF0rPTI7CiAgICAgIHN6dWxvW3BdWzBdPXExOwogICAgICBzenVsb1twXVsxXT1xMjsKICAgICAgdmFuX3N6dWxvW3BdPTE7CiAgICAgIHZhbl9neWVyZWtbcTFdPTE7CiAgICAgIHZhbl9neWVyZWtbcTJdPTE7CiAgIH0KfQoKaW50IG1haW4oKXsKICAgQmVvbHZhcygpOwogICB2ZWN0b3I8aW50PiBuZXZbbl07CiAgIGludCBjbnQsZCxpLGoscCxxLHNpLHNpMixzaXplLHN6dWxvMSxzenVsbzIsbWVseXNlZz0wLHNvbFttYXhuXTsKICAgdW5zaWduZWQgaW50IGJpdFszMl0sKipvcyxhbnNbbWF4bisxXTsKCiAgIC8vIHRvcG9sb2dpa3VzIHNvcnJlbmQgbWVna2VyZXPDqXNlCiAgIGZvciAoaW50IHA9MTtwPD1uO3ArKykKICAgICAgaWYoQmVGb2tbcF09PTApCiAgICAgICAgIG5ldlswXS5wdXNoX2JhY2socCk7CgogICB3aGlsZShuZXZbbWVseXNlZ10uc2l6ZSgpPjApewogICAgIHNpPW5ldlttZWx5c2VnXS5zaXplKCk7IAogICAgIGZvcihpPTA7aTxzaTtpKyspewogICAgICAgICBwPW5ldlttZWx5c2VnXVtpXTsKCSBzaTI9R1twXS5zaXplKCk7CgkgZm9yKGo9MDtqPHNpMjtqKyspewoJICAgIHE9R1twXVtqXTsKICAgICAgICAgICAgQmVGb2tbcV0tLTsKICAgICAgICAgICAgaWYoQmVGb2tbcV09PTApCiAgICAgICAgICAgICAgIG5ldlttZWx5c2VnKzFdLnB1c2hfYmFjayhxKTsKICAgICAgICAgfQogICAgICB9CiAgICAgIG1lbHlzZWcrKzsKICAgfQogICAKICAgYml0WzBdPTE7Zm9yKGk9MTtpPDMyO2krKyliaXRbaV09MipiaXRbaS0xXTsKICAgCiAgIHNpPShuKzMyKS8zMjsKICAgb3M9KHVuc2lnbmVkIGludCoqKW1hbGxvYygobisxKSpzaXplb2YodW5zaWduZWQgaW50KikpOwogICBmb3IoaT0wO2k8PW47a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