#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<int,int>
#define MP make_pair
#define pb push_back
#define INF 1e8
#define M(x) memset(x,0,sizeof(x))
vector<int> graph[100005],graph1[100005];
int comp[100005],indeg[100005],check[100005],n;
void dfs(int s){
check[s]=1;
for(auto it:graph[s]){
if(!check[it]) dfs(it);
}
}
void dfs1(int s,int cl){
comp[s]=cl;
for(auto it:graph1[s]){
if(!comp[it]) {comp[it]=cl,dfs1(it,cl);}
}
}
void in() {
REP(i,1,n){
for(auto it:graph[i]){
if(comp[i]!=comp[it]) indeg[comp[it]]++;
}
}
}
void solve(){
stack<int> s;
REP(i,1,n){
if(!check[i]){dfs(i);s.push(i);}
}
int clr=1;
while(!s.empty()){
int it=s.top();s.pop();
dfs1(it,clr);
clr++;
}
in();
int cnt=0,p;
REP(i,1,clr-1){if(!indeg[i]) {cnt++;p=i;}}
if(cnt==1){vector<int> v; cnt=0;REP(i,1,n) if(comp[i]==p) v.pb(i),cnt++; cout<<cnt<<endl;sort(v.begin(),v.end());for(auto i:v) cout<<i<<" "; cout<<endl;}
else
cout<<0<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t,x,y,a,b;
{
cin>>n>>x;
M(graph);M(graph1);M(comp);M(indeg);M(check);
REP(i,1,n){
REP(j,0,x-1){
cin>>a>>b;
graph1[a].pb(b);
graph[b].pb(a);
}
}
solve();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgUkVQKGksYSxiKSBmb3IoaW50IGk9YTtpPD1iO2krKykKI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgojZGVmaW5lIE1QIG1ha2VfcGFpcgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIElORiAxZTgKI2RlZmluZSBNKHgpIG1lbXNldCh4LDAsc2l6ZW9mKHgpKQoKdmVjdG9yPGludD4gZ3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