#include <iostream>
#include <vector>
#include <queue> 
using namespace std;
const int N=109;
vector<int> graph[N];
bool mark[N];
queue< pair<int,int> > q;
int main()
{
	int n;
	cin>>n;
	vector<int> ans[3];
	for(int i=1;i<=n;++i)
	{
		int b;
		cin>>b;
		while(b!=0)
		{
			graph[i].push_back(b);
			cin>>b;
		}
	}
	for(int i=1;i<=n;++i)
	{
		if(mark[i]==false)
		{
			q.push(make_pair(i,1));
			ans[1].push_back(i);
			mark[i]=true;
			while(!q.empty())
			{
				pair<int,int> p=q.front();
				q.pop();
				int t;
				if(p.second==1)
					t=2;
				else
					t=1;
				for(int i=0;i<graph[p.first].size();++i)
					if(mark[graph[p.first][i]]==false)
					{
						mark[graph[p.first][i]]=true;
						q.push(make_pair(graph[p.first][i],t));
						ans[t].push_back(graph[p.first][i]);
					}
			}
		}
	}
	bool team1[N],team2[N];
	for(int i=0;i<ans[1].size();++i)
		team1[ans[1][i]]=true;
	for(int i=0;i<ans[2].size();++i)
		team2[ans[2][i]]=true;
	bool check=true;
	for(int i=0;i<ans[1].size();++i)
	{
		check=false;
		for(int j=0;j<graph[ans[1][i]].size();++j)
			if(team2[graph[ans[1][i]][j]]==true)
				check=true;
		if(!check)
			break;
	}
	if(!check)
		cout<<0;
	else
	{
		cout<<ans[1].size()<<endl;
		for(int i=0;i<ans[1].size();++i)
			cout<<ans[1][i]<<" ";
	}
	return 0;

}