#include<bits/stdc++.h>
#define For(aa,bb,cc) for(int aa=(bb);aa<=(int)(cc);++aa)
#define Forr(aa,bb,cc) for(int aa=(bb);aa>=(int)(cc);--aa)
using namespace std;
const int maxn=1e5+10;
int n,m,flag; int ne[maxn<<1],to[maxn<<1],be[maxn],e;
int deg[maxn];
bool sign[maxn];
int vis[maxn];
vector<int>G[maxn];
queue<int>q;

void add(int x,int y){
	to[++e]=y,ne[e]=be[x],be[x]=e;
}

void dfs(int node){
	if(flag) return ;
	if(vis[node]==-1){
		flag=1;
		return ;
	}
	vis[node]=-1;
	For(i,0,G[node].size()-1){
		int u=G[node][i];
		if(vis[u]==0 || vis[u]==-1) dfs(u);
		if(flag) return ;
		add(u,node),++deg[node];
	}
	vis[node]=1;
}

void topo(){
	int ans[maxn],tot=0;
	For(i,1,n) if(vis[i] && !deg[i]) q.push(i);
	while(!q.empty()){
		int u=q.front();q.pop();
		ans[++tot]=u;
		for(int i=be[u];i;i=ne[i]){
			int v=to[i];
			--deg[v];
			if(!deg[v]) q.push(v);
		} }
	printf("%d\n",tot);
	For(i,1,tot) printf("%d ",ans[i]);puts("");
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int x,y;
	scanf("%d%d",&n,&m);
	For(i,1,m) scanf("%d",&x),sign[x]=1;
	For(i,1,n){
		scanf("%d",&x);
		For(j,1,x) scanf("%d",&y),G[i].push_back(y);
	}
	//For(i,1,n) For(j,0,G[i].size()-1) cout<<i<<" "<<G[i][j]<<endl;
	For(i,1,n) if(sign[i] && !vis[i]) dfs(i);
	if(flag){
		puts("-1");
		return 0;
	}
	topo();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=1e4+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n,k;
bool key[maxn];
vector<int>g[maxn];int in[maxn];vector<int>kv;bool done[maxn];vector<int>vv;
void bfs(int i)
{
	queue<int>q;
	if(done[i])return;
	q.push(i);
	while(!q.empty())
	{
		int c=q.front();q.pop();vv.pb(c);
		done[c]=1;
		for(auto&w:g[c])
		{
			if(!done[w])q.push(w);
		}
	}
}
int main()
{
	fast;cin>>n>>k;_for(t,0,k)
	{
		int x;cin>>x;key[x]=1;
	}
	_for(i,1,n+1)
	{
		int t;cin>>t;
		_for(j,0,t)
		{
			int x;cin>>x;g[i].pb(x);++in[x];
		}
	}
	queue<int>q;vector<int>v;_for(t,1,n+1)if(!in[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();v.pb(c);
		if(key[c])kv.pb(c);
		for(auto&w:g[c])
		{
			if(!--in[w])
			{
				q.push(w);
			}
		}
	}
	if(v.size()<n)return cout<<-1,0;
	for(auto&w:kv)bfs(w);
	reverse(vv.begin(),vv.end());
	cout<<vv.size()<<"\n";for(auto&w:vv)cout<<w<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=1e4+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n,k;
bool key[maxn];
vector<int>g[maxn];int in[maxn];vector<int>kv;bool done[maxn];vector<int>vv;
void bfs(int i)
{
	if(done[i])return;
	queue<int>q;q.push(i);
	done[i]=1;while(!q.empty())
	{
		int c=q.front();q.pop();
		for(auto&e:g[c])
		{
			if(!done[e])done[e]=1,q.push(e);
		}
	}
}
int main()
{
	fast;cin>>n>>k;_for(t,0,k)
	{
		int x;cin>>x;key[x]=1;
	}
	_for(i,1,n+1)
	{
		int t;cin>>t;
		_for(j,0,t)
		{
			int x;cin>>x;g[i].pb(x);++in[x];
		}
	}
	queue<int>q;vector<int>v;_for(t,1,n+1)if(!in[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();v.pb(c);
		if(key[c])kv.pb(c);
		for(auto&w:g[c])
		{
			if(!--in[w])
			{
				q.push(w);
			}
		}
	}
	if(v.size()<n)return cout<<-1,0;
	for(auto&w:kv)bfs(w);reverse(v.begin(),v.end());
	for(auto&w:v)
	{
		if(done[w])vv.pb(w);
	}
	cout<<vv.size()<<"\n";for(auto&w:vv)cout<<w<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=1e4+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n,k;
bool key[maxn];
vector<int>g[maxn];int in[maxn];vector<int>kv;bool done[maxn];vector<int>vv;
void bfs(int i)
{
	queue<int>q;
	if(done[i])return;
	q.push(i);done[i]=1;
	while(!q.empty())
	{
		int c=q.front();q.pop();vv.pb(c);
		for(auto&w:g[c])
		{
			if(!done[w])q.push(w),done[w]=1;
		}
	}
}
int main()
{
	fast;cin>>n>>k;_for(t,0,k)
	{
		int x;cin>>x;key[x]=1;
	}
	_for(i,1,n+1)
	{
		int t;cin>>t;
		_for(j,0,t)
		{
			int x;cin>>x;g[i].pb(x);++in[x];
		}
	}
	queue<int>q;vector<int>v;_for(t,1,n+1)if(!in[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();v.pb(c);
		if(key[c])kv.pb(c);
		for(auto&w:g[c])
		{
			if(!--in[w])
			{
				q.push(w);
			}
		}
	}
	if(v.size()<n)return cout<<-1,0;
	for(auto&w:kv)bfs(w);
	reverse(vv.begin(),vv.end());
	cout<<vv.size()<<"\n";for(auto&w:vv)cout<<w<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=1e4+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n,k;
bool key[maxn];
vector<int>g[maxn];int in[maxn];vector<int>kv;bool done[maxn];vector<int>vv;
int main()
{
	fast;cin>>n>>k;_for(t,0,k)
	{
		int x;cin>>x;key[x]=1;
	}
	_for(i,1,n+1)
	{
		int t;cin>>t;
		_for(j,0,t)
		{
			int x;cin>>x;g[i].pb(x);++in[x];
		}
	}
	queue<int>q;vector<int>v;_for(t,1,n+1)if(!in[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();v.pb(c);
		if(key[c])kv.pb(c);
		for(auto&w:g[c])
		{
			if(!--in[w])
			{
				q.push(w);
			}
		}
	}
	if(v.size()<n)return cout<<-1,0;
	reverse(kv.begin(),kv.end());for(auto&w:kv)q.push(w),done[w]=1;
	while(!q.empty())
	{
		int c=q.front();q.pop();vv.pb(c);
		for(auto&w:g[c])
		{
			if(!done[w])done[w]=1,q.push(w);
		}
	}
	cout<<vv.size()<<"\n";for(auto&w:vv)cout<<w<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=1e4+10;
const double PI=acos(-1.0);
const double eps=1e-8;
int n,k;
bool key[maxn];
vector<int>g[maxn];int in[maxn];vector<int>kv;bool done[maxn];vector<int>vv;
void bfs(int i)
{
	if(done[i])return;
	queue<int>q;q.push(i);
	done[i]=1;while(!q.empty())
	{
		int c=q.front();q.pop();
		for(auto&e:g[c])
		{
			if(!done[e])done[e]=1,q.push(e);
		}
	}
}
bool has[maxn];
int main()
{
	fast;cin>>n>>k;_for(t,0,k)
	{
		int x;cin>>x;key[x]=1;
	}
	_for(i,1,n+1)
	{
		int t;cin>>t;
		_for(j,0,t)
		{
			int x;cin>>x;g[i].pb(x);
		}
	}
	vector<int>re;
	_for(i,1,n+1)
	{
		if(key[i]&&!has[i])
		{
			queue<int>qq;qq.push(i);has[i]=1;
			while(!qq.empty())
			{
				int c=qq.front();qq.pop();
				re.pb(c);
				for(auto&w:g[c])
				{
					if(!has[w])has[w]=1,qq.push(w);
				}
			}
		}
	}
	for(auto&w:re)
	{
		for(auto&q:g[w])++in[q];
	}
	queue<int>q;vector<int>v;for(auto&t:re)if(!in[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();
		v.pb(c);
		for(auto&w:g[c])
		{
			if(!--in[w])
			{
				q.push(w);
			}
		}
	}
	if(v.size()<re.size())return cout<<-1,0;
	reverse(v.begin(),v.end());
	cout<<v.size()<<"\n";
	for(auto&w:v)cout<<w<<" ";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define f(i,n) for(i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcount(n)
#define endl '\n'
const ll N=1e5+5,mod=1e9+7,bit=60;

ll vis[N]={0},must[N]={0},n,k;
std::vector<ll> adj[N],path;
bool pos=1;

bool iscycle(ll u)
{
	if(vis[u]==1)
	{
		return 1;
	}
	if(vis[u]==2)
	{
		return 0;
	}
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(iscycle(v))
		{
			return 1;
		}
	}
	vis[u]=2;
	return 0;
}

void check()
{
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			if(iscycle(i))
			{
				pos=0;
				return;
			}
		}
	}
}

void dfs(ll u)
{
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(!vis[v])
		{
			dfs(v);
		}
	}
	path.pb(u);
}

signed main()
{
    fast;
    cin>>n>>k;
    ll i,u,v;
    for(i=1;i<=k;i++)
    {
    	cin>>u;
    	must[u]=1;
    }
    for(i=1;i<=n;i++)
    {
    	cin>>u;
    	while(u--)
    	{
    		cin>>v;
    		adj[i].pb(v);
    	}
    }
    check();
    if(!pos)
    {
    	return cout<<-1,0;
    }
    memset(vis,0,sizeof(vis));
    for(i=1;i<=n;i++)
    {
    	if(must[i] and !vis[i])
    	{
    		dfs(i);
    	}
    }
    cout<<path.size()<<endl;
    for(auto x:path)
    {
    	cout<<x<<' ';
    }
    cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define f(i,n) for(i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcount(n)
#define endl '\n'
const ll N=1e5+5,mod=1e9+7,bit=60;

ll vis[N]={0},must[N]={0},n,k;
std::vector<ll> adj[N],path;
bool pos=1,fromthis=0;

bool iscycle(ll u)
{
	if(vis[u]==1)
	{
		fromthis|=(must[u]);
		return 1;
	}
	if(vis[u]==2)
	{
		return 0;
	}
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(iscycle(v))
		{
			fromthis|=(must[v]);
			return 1;
		}
	}
	vis[u]=2;
	return 0;
}

void check()
{
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			fromthis=0;
			if(iscycle(i) and fromthis)
			{
				pos=0;
				return;
			}
		}
	}
}

void dfs(ll u)
{
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(!vis[v])
		{
			dfs(v);
		}
	}
	path.pb(u);
}

signed main()
{
    fast;
    cin>>n>>k;
    ll i,u,v;
    for(i=1;i<=k;i++)
    {
    	cin>>u;
    	must[u]=1;
    }
    for(i=1;i<=n;i++)
    {
    	cin>>u;
    	while(u--)
    	{
    		cin>>v;
    		adj[i].pb(v);
    	}
    }
    check();
    if(!pos)
    {
    	return cout<<-1,0;
    }
    memset(vis,0,sizeof(vis));
    for(i=1;i<=n;i++)
    {
    	if(must[i] and !vis[i])
    	{
    		dfs(i);
    	}
    }
    cout<<path.size()<<endl;
    for(auto x:path)
    {
    	cout<<x<<' ';
    }
    cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define f(i,n) for(i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcount(n)
#define endl '\n'
const ll N=1e5+5,mod=1e9+7,bit=60;

ll vis[N]={0},must[N]={0},n,k;
std::vector<ll> adj[N],path;
bool pos=1,fromthis=0;

bool iscycle(ll u)
{
	if(vis[u]==1)
	{
		fromthis|=(must[u]);
		return 1;
	}
	if(vis[u]==2)
	{
		return 0;
	}
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(iscycle(v))
		{
			fromthis|=(must[v]);
			return 1;
		}
	}
	vis[u]=2;
	return 0;
}

void check()
{
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			fromthis=0;
			if(iscycle(i) and fromthis)
			{
				pos=0;
				return;
			}
		}
	}
}

void dfs(ll u)
{
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(!vis[v])
		{
			dfs(v);
		}
	}
	path.pb(u);
}

void tour(ll u)
{
	must[u]=1;
	for(auto v:adj[u])
	{
		if(!must[v])
		{
			tour(v);
		}
	}
}

signed main()
{
    fast;
    cin>>n>>k;
    ll i,u,v;
    for(i=1;i<=k;i++)
    {
    	cin>>u;
    	must[u]=1;
    }
    for(i=1;i<=n;i++)
    {
    	cin>>u;
    	while(u--)
    	{
    		cin>>v;
    		adj[i].pb(v);
    	}
    }
    for(i=1;i<=n;i++)
    {
    	if(must[i])
    	{
    		tour(i);
    	}
    }
    check();
    if(!pos)
    {
    	return cout<<-1,0;
    }
    memset(vis,0,sizeof(vis));
    for(i=1;i<=n;i++)
    {
    	if(must[i] and !vis[i])
    	{
    		dfs(i);
    	}
    }
    cout<<path.size()<<endl;
    for(auto x:path)
    {
    	cout<<x<<' ';
    }
    cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vll vector<ll>
#define vvll vector<vll>
template<typename T, typename U>
static inline void amin(T &x, U y){
    if(x>y)
        x = y;
}
template<typename T, typename U>
static inline void amax(T &x, U y){
    if(x<y)
        x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+15;
ll INF = 2e18L+15;
const int mod = 1e9+7;
const int V = 1e5+50;

vi g[V];

int dfs(int u, vi & vis, stack <int> & stk){
    vis[u] = 1;
    int flag = 1;
    for(auto ne : g[u]){
        if(vis[ne]==0){
            flag = dfs(ne, vis, stk);
        }else if(vis[ne]==1){
            return 0;
        }
    }
    vis[u] = 2;
    stk.push(u);
    return flag;
}

int topoSort(int n, vi & sorted){
    vi vis(n+1, 0);
    stack <int> stk;
    int flag = 1;
    for(int i = 1; i <= n; ++i)
        if(vis[i]==0){
            int x = dfs(i, vis, stk);
            if(x==0){
                flag = 0;
            }
        }
    while(!stk.empty()){
        sorted.push_back(stk.top());
        stk.pop();
    }
    return flag;
}

int main(){
    int n, k, t, x;
    cin>> n>> k;
    vi req(n+1, 0);
    rep(i, k){
        cin>> x;
        req[x] = 1;
    }
    vi prev[n+1];
    for(int course = 1; course <= n; ++course){
        cin>> t;
        while (t--)
        {
            cin>> x;
            g[x].push_back(course);
            prev[course].push_back(x);
        }
    }
    vi sorted;
    int ok = topoSort(n, sorted);
    stack <int> ans;
    for(int i = sorted.size()-1; i >= 0; --i){
        int cur = sorted[i];
        if(req[cur]){
            ans.push(cur);
            for(int x : prev[cur]){
                req[x] = 1;
            }
        }
    }
    if(!ok){
        cout << "-1\n";
        return 0;
    }
    cout << ans.size() << "\n";
    while(!ans.empty()){
        cout << ans.top() << " ";
        ans.pop();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vll vector<ll>
#define vvll vector<vll>
template<typename T, typename U>
static inline void amin(T &x, U y){
    if(x>y)
        x = y;
}
template<typename T, typename U>
static inline void amax(T &x, U y){
    if(x<y)
        x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+15;
ll INF = 2e18L+15;
const int mod = 1e9+7;
const int V = 1e5+50;

vi g[V];
vi req(V+1, 0);

int dfs(int u, vi & vis, stack <int> & stk){
    vis[u] = 1;
    int flag = 1;
    for(auto ne : g[u]){
        if(vis[ne]==0){
            amin(flag, dfs(ne, vis, stk));
        }else if(vis[ne]==1){
            if(req[u] || req[ne])
                amin(flag, 0);
        }
    }
    vis[u] = 2;
    stk.push(u);
    return flag;
}

int topoSort(int n, vi & sorted){
    vi vis(n+1, 0);
    stack <int> stk;
    int flag = 1;
    for(int i = 1; i <= n; ++i)
        if(vis[i]==0){
            int x = dfs(i, vis, stk);
            if(x==0){
                flag = 0;
            }
        }
    while(!stk.empty()){
        sorted.push_back(stk.top());
        stk.pop();
    }
    return flag;
}

int main(){
    int n, k, t, x;
    cin>> n>> k;
    rep(i, k){
        cin>> x;
        req[x] = 1;
    }
    vi prev[n+1];
    for(int course = 1; course <= n; ++course){
        cin>> t;
        while (t--)
        {
            cin>> x;
            g[x].push_back(course);
            if(req[course]){
                req[x] = 1;
            }
        }
    }
    vi sorted;
    int ok = topoSort(n, sorted);
    stack <int> ans;
    for(int i = sorted.size()-1; i >= 0; --i){
        int cur = sorted[i];
        if(req[cur]){
            ans.push(cur);
        }
    }
    if(!ok){
        cout << "-1\n";
        return 0;
    }
    cout << ans.size() << "\n";
    while(!ans.empty()){
        cout << ans.top() << " ";
        ans.pop();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vll vector<ll>
#define vvll vector<vll>
template<typename T, typename U>
static inline void amin(T &x, U y){
    if(x>y)
        x = y;
}
template<typename T, typename U>
static inline void amax(T &x, U y){
    if(x<y)
        x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+15;
ll INF = 2e18L+15;
const int mod = 1e9+7;
const int V = 1e5+50;

vi g[V];

int dfs(int u, vi & vis, stack <int> & stk){
    vis[u] = 1;
    int flag = 1;
    for(auto ne : g[u]){
        if(vis[ne]==0){
            amin(flag, dfs(ne, vis, stk));
        }else if(vis[ne]==1){
            return 0;
        }
    }
    vis[u] = 2;
    stk.push(u);
    return flag;
}

int topoSort(int n, vi & sorted){
    vi vis(n+1, 0);
    stack <int> stk;
    int flag = 1;
    for(int i = 1; i <= n; ++i)
        if(vis[i]==0){
            int x = dfs(i, vis, stk);
            if(x==0){
                flag = 0;
            }
        }
    while(!stk.empty()){
        sorted.push_back(stk.top());
        stk.pop();
    }
    return flag;
}

int main(){
    int n, k, t, x;
    cin>> n>> k;
    vi req(n+1, 0);
    rep(i, k){
        cin>> x;
        req[x] = 1;
    }
    vi prev[n+1];
    for(int course = 1; course <= n; ++course){
        cin>> t;
        while (t--)
        {
            cin>> x;
            g[x].push_back(course);
            prev[course].push_back(x);
        }
    }
    vi sorted;
    int ok = topoSort(n, sorted);
    stack <int> ans;
    for(int i = sorted.size()-1; i >= 0; --i){
        int cur = sorted[i];
        if(req[cur]){
            ans.push(cur);
            for(int x : prev[cur]){
                req[x] = 1;
            }
        }
    }
    if(!ok){
        cout << "-1\n";
        return 0;
    }
    cout << ans.size() << "\n";
    while(!ans.empty()){
        cout << ans.top() << " ";
        ans.pop();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vll vector<ll>
#define vvll vector<vll>
template<typename T, typename U>
static inline void amin(T &x, U y){
    if(x>y)
        x = y;
}
template<typename T, typename U>
static inline void amax(T &x, U y){
    if(x<y)
        x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9+15;
ll INF = 2e18L+15;
const int mod = 1e9+7;
const int V = 1e5+50;

vi g[V];

int dfs(int u, vi & vis, vector <int> & ans){
    vis[u] = 1;
    int flag = 1;
    for(auto ne : g[u]){
        if(vis[ne]==0){
            amin(flag, dfs(ne, vis, ans));
        }else if(vis[ne]==1){
            return 0;
        }
    }
    vis[u] = 2;
    ans.push_back(u);
    return flag;
}

int main(){
    int n, k, t, x;
    cin>> n>> k;
    vi req(n+1, 0);
    rep(i, k){
        cin>> x;
        req[x] = 1;
    }
    vi prev[n+1];
    for(int course = 1; course <= n; ++course){
        cin>> t;
        while (t--)
        {
            cin>> x;
            g[course].push_back(x);
        }
    }
    vi sorted;
    int ok = 1;
    vector <int> ans;
    vi vis(n+1,0);
  for(int i=1;i<=n;++i)
  if(req[i] && !vis[i])
  amin(ok, dfs(i,vis,ans));
    if(!ok){
        cout << "-1\n";
        return 0;
    }
    cout << ans.size() << "\n";
    rep(i,ans.size()){
        cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N = 1e5;
vector<vector<int>> adj(N);
vector<int> vis(N), color(N), parent(N, -1);
vector<int> ans;
int cycle_start = -1, cycle_end;

void dfs(int i)
{
    vis[i] = 1;
    for (auto x : adj[i])
    {
        if (!vis[x])
        {
            dfs(x);
            ans.pb(x);
        }
    }
}

bool check_cycle(int v)
{
    color[v] = 1;
    for (int u : adj[v])
    {
        if (color[u] == 0)
        {
            parent[u] = v;
            if (check_cycle(u))
                return true;
        }
        else if (color[u] == 1)
        {
            cycle_end = v;
            cycle_start = u;
            return true;
        }
    }
    color[v] = 2;
    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<int> a(k);
    for (int i = 0; i < k; i++)
    {
        cin >> a[i];
        --a[i];
    }
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        for (int j = 0; j < t; j++)
        {
            int u;
            cin >> u;
            --u;
            adj[i].pb(u);
        }
    }

    for (int v = 0; v < n; v++)
    {
        if (color[v] == 0 && check_cycle(v))
            break;
    }

    if (cycle_start != -1)
    {
        cout << "-1\n";
        return 0;
    }

    for (int i = 0; i < k; i++)
    {
        if (!vis[a[i]])
        {
            dfs(a[i]);
            ans.pb(a[i]);
        }
    }

    for (auto x : ans)
        cout << x + 1 << " ";
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N = 1e5;
vector<vector<int>> adj(N);
vector<int> vis(N), color(N), parent(N, -1);
vector<int> ans;
int cycle_start = -1, cycle_end;

void dfs(int i)
{
    vis[i] = 1;
    for (auto x : adj[i])
    {
        if (!vis[x])
        {
            dfs(x);
            ans.pb(x);
        }
    }
}

bool check_cycle(int v)
{
    color[v] = 1;
    for (int u : adj[v])
    {
        if (color[u] == 0)
        {
            parent[u] = v;
            if (check_cycle(u))
                return true;
        }
        else if (color[u] == 1)
        {
            cycle_end = v;
            cycle_start = u;
            return true;
        }
    }
    color[v] = 2;
    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<int> a(k);
    for (int i = 0; i < k; i++)
    {
        cin >> a[i];
        --a[i];
    }
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        for (int j = 0; j < t; j++)
        {
            int u;
            cin >> u;
            --u;
            adj[i].pb(u);
        }
    }

    for (int v = 0; v < n; v++)
    {
        if (color[v] == 0 && check_cycle(v))
            break;
    }

    if (cycle_start != -1)
    {
        cout << "-1\n";
        return 0;
    }

    for (int i = 0; i < k; i++)
    {
        if (!vis[a[i]])
        {
            dfs(a[i]);
            ans.pb(a[i]);
        }
    }
    cout << ans.size() << "\n";
    for (auto x : ans)
        cout << x + 1 << " ";
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N = 1e5;
vector<vector<int>> adj(N);
vector<int> vis(N), color(N), parent(N, -1);
vector<int> ans;
int cycle_start = -1, cycle_end;

void dfs(int i)
{
    vis[i] = 1;
    for (auto x : adj[i])
    {
        if (!vis[x])
        {
            dfs(x);
            ans.pb(x);
        }
    }
}

bool check_cycle(int v)
{
    color[v] = 1;
    for (int u : adj[v])
    {
        if (color[u] == 0)
        {
            parent[u] = v;
            if (check_cycle(u))
                return true;
        }
        else if (color[u] == 1)
        {
            cycle_end = v;
            cycle_start = u;
            return true;
        }
    }
    color[v] = 2;
    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<int> a(k);
    for (int i = 0; i < k; i++)
    {
        cin >> a[i];
        --a[i];
    }
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        for (int j = 0; j < t; j++)
        {
            int u;
            cin >> u;
            --u;
            adj[i].pb(u);
        }
    }

    for (int i = 0; i < k; i++)
    {
        cycle_start = -1;
        if (!vis[a[i]])
        {
            bool y = (color[a[i]] == 0) and (check_cycle(a[i]));
            if (y and cycle_start != -1)
            {
                cout << "-1\n";
                return 0;
            }
            dfs(a[i]);
            ans.pb(a[i]);
        }
    }

    cout << ans.size() << "\n";
    for (auto x : ans)
        cout << x + 1 << " ";
    cout << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pr;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(i,k,n) for(ll i=k;i<n;i++)
#define fr(i,n,k) for(ll i=n-1;i>=k;i--)
#define pb push_back
#define mxi(v) (max_element((v).begin(),(v).end())-(v).begin())
#define mni(v) (min_element((v).begin(),(v).end())-(v).begin())
#define mxe(v) *max_element((v).begin(),(v).end())
#define mne(v) *min_element((v).begin(),(v).end())
#define sort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).begin(),(v).end(),greater<int>())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
ve<ve<ll>>v; ve<bool>b; ve<ll>a,c;
bool dfs(ll x,ll y) {
    b[x]=true;
    c.pb(x); bool f=true;
    for(ll t:v[x]) {
        if(t!=y) {
            if(!b[t]) {
                f&=dfs(t,x);
            }
            else {f=false;}
        }
    }
    return f;
}
int main() {
    fast
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ll t=1; //cin>>t;
    while(t--) {
        ll n,k,x,y,m;
        cin>>n>>k;
        a.resize(k);
        f(i,0,k) {cin>>a[i];}
        v.resize(n+1); b.resize(n+1,false);
        f(i,1,n+1) {
            cin>>m;
            f(j,0,m) {
                cin>>x; v[i].pb(x);
            }
        }
        for(ll y:a) {
            if(!b[y]) {
                if(!dfs(y,0)) {cout<<"-1"<<endl; return 0;}
            }
        }
        cout<<c.size()<<endl;
        for(ll x:c) {cout<<x<<" ";}
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pr;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(i,k,n) for(ll i=k;i<n;i++)
#define fr(i,n,k) for(ll i=n-1;i>=k;i--)
#define pb push_back
#define mxi(v) (max_element((v).begin(),(v).end())-(v).begin())
#define mni(v) (min_element((v).begin(),(v).end())-(v).begin())
#define mxe(v) *max_element((v).begin(),(v).end())
#define mne(v) *min_element((v).begin(),(v).end())
#define sort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).begin(),(v).end(),greater<int>())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
ve<ve<ll>>v; ve<ll>b; ve<ll>a,c; bool f=true;
void dfs(ll x) {
    if(!b[x]) {
        b[x]=1;
        for(ll t:v[x]) {dfs(t);}
        b[x]=2; c.pb(x);
    }
    else if(b[x]==1) {f=false;}
}
int main() {
    fast
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ll t=1; //cin>>t;
    while(t--) {
        ll n,k,x,y,m;
        cin>>n>>k;
        a.resize(k);
        f(i,0,k) {cin>>a[i];}
        v.resize(n+1); b.resize(n+1,0);
        f(i,1,n+1) {
            cin>>m;
            f(j,0,m) {
                cin>>x; v[i].pb(x);
            }
        }
        for(ll y:a) {
            if(!b[y]) {
                dfs(y);
                if(!f) {cout<<"-1"<<endl; return 0;}
            }
        }
        cout<<c.size()<<endl;
        for(ll x:c) {cout<<x<<" ";}
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pr;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(i,k,n) for(ll i=k;i<n;i++)
#define fr(i,n,k) for(ll i=n-1;i>=k;i--)
#define pb push_back
#define mxi(v) (max_element((v).begin(),(v).end())-(v).begin())
#define mni(v) (min_element((v).begin(),(v).end())-(v).begin())
#define mxe(v) *max_element((v).begin(),(v).end())
#define mne(v) *min_element((v).begin(),(v).end())
#define sort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).begin(),(v).end(),greater<int>())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
ve<ve<ll>>v; ve<bool>b; ve<ll>a,c;
bool dfs(ll x,ll y) {
    b[x]=true;
    bool f=true;
    for(ll t:v[x]) {
        if(t!=y) {
            if(!b[t]) {
                f&=dfs(t,x);
            }
            else {f=false;}
        }
    }
    c.pb(x);
    return f;
}
int main() {
    fast
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ll t=1; //cin>>t;
    while(t--) {
        ll n,k,x,y,m;
        cin>>n>>k;
        a.resize(k);
        f(i,0,k) {cin>>a[i];}
        v.resize(n+1); b.resize(n+1,false);
        f(i,1,n+1) {
            cin>>m;
            f(j,0,m) {
                cin>>x; v[i].pb(x);
            }
        }
        for(ll y:a) {
            if(!b[y]) {
                if(!dfs(y,0)) {cout<<"-1"<<endl; return 0;}
            }
        }
        cout<<c.size()<<endl;
        for(ll x:c) {cout<<x<<" ";}
    }
return 0;
}


#include "bits/stdc++.h"

using namespace std;
using vi = vector<int>;
const int MAXN = 1e5 + 5;

int n, k;
vi adj[MAXN];
bool visited[MAXN];
int parent[MAXN];
char color[MAXN];
vi ans;

bool dfs(int v) {
    color[v] = true;
    for (int u : adj[v]) {
			if (color[u] == 0){
				parent[u] = 0;
				if(dfs(u))
					return 1;

			} else if (color[u] == 1){
				return 1;
			}
    }
		color[v] = 2;
    ans.push_back(v);
		return false;
}

int main(){
	cin >> n >> k;
	vi nds(k, 0);

	for(int i = 0;i < k;i++){
		cin >> nds[i];
	}

	for(int i = 1;i <= n;i++){
		int reqs;
		cin >> reqs;
		for(int j = 0;j < reqs;j++){
			int src;
			cin >> src;
			adj[i].push_back(src);
		}
	}

	for (auto i : nds) {
		if (color[i] == 0 and dfs(i)) {
			cout << -1 << "\n";
			return 0;
		}
	}

	cout << ans.size() << "\n";
	for(auto val : ans)
		cout << val << " ";
	cout << "\n";

}


#include "bits/stdc++.h"

using namespace std;
using vi = vector<int>;
const int MAXN = 1e5 + 5;

int n, k;
vi adj[MAXN];
bool visited[MAXN];
int parent[MAXN];
char color[MAXN];
vi ans;

bool dfs(int v) {
    color[v] = true;
    for (int u : adj[v]) {
			if (color[u] == 0){
				parent[u] = 0;
				if(dfs(u))
					return 1;

			} else if (color[u] == 1){
				return 1;
			}
    }
		color[v] = 2;
    ans.push_back(v);
		return false;
}

int main(){
	cin >> n >> k;
	vi nds(k, 0);

	for(int i = 0;i < k;i++){
		cin >> nds[i];
	}

	for(int i = 1;i <= n;i++){
		int reqs;
		cin >> reqs;
		for(int j = 0;j < reqs;j++){
			int src;
			cin >> src;
			adj[i].push_back(src);
		}
	}

	for (auto i : nds) {
		if (color[i] == 0 and dfs(i)) {
			cout << -1 << "\n";
			return 0;
		}
	}

	for(auto val : ans)
		cout << val << " ";
	cout << "\n";

}


#include "bits/stdc++.h"
using namespace std;
#define  pb  push_back
typedef long long int ll;
const int N=1e5+10,inf=1e7;
vector<int>vec[N],rs;
int vs[N],col[N];
void dfs(int u)
{
    if(col[u]==2)return;
    col[u]=1;
    for(auto v:vec[u]){
        if(col[v]==1){
            cout<<"-1\n";
            exit(0);
        }
        dfs(v);
    }
    col[u]=2;
    rs.pb(u);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    int n,m;cin>>n>>m;
    int Arr[m+1];
    for(int i=1;i<=m;i++){
        cin>>Arr[i];
    }
    for(int i=1;i<=n;i++){
        int p;cin>>p;
        while(p--){
            int x;cin>>x;
            vec[i].pb(x);
        }
    }
    for(int i=1;i<=m;i++){
        if(col[Arr[i]]==2)continue;
        dfs(Arr[i]);
    }
    cout<<rs.size()<<"\n";
    for(auto x:rs)cout<<x<<" ";
    cout<<"\n";

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define  pb  push_back
typedef long long int ll;
const int N=1e5+10,inf=1e7;
vector<int>vec[N],rs;
int vs[N],col[N];
void dfs(int u)
{
    col[u]=1;
    for(auto v:vec[u]){
        if(col[v]==1){
            cout<<"-1\n";
            exit(0);
        }
        dfs(v);
    }
    col[u]=2;
    rs.pb(u);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    int n,m;cin>>n>>m;
    int Arr[m+1];
    for(int i=1;i<=m;i++){
        cin>>Arr[i];
    }
    for(int i=1;i<=n;i++){
        int p;cin>>p;
        while(p--){
            int x;cin>>x;
            vec[i].pb(x);
        }
    }
    for(int i=1;i<=m;i++){
        if(col[Arr[i]]==2)continue;
        dfs(Arr[i]);
    }
    cout<<rs.size()<<"\n";
    for(auto x:rs)cout<<x<<" ";
    cout<<"\n";

    return 0;
}


                                    //  IT'S NEVER TOO LATE...

#include <bits/stdc++.h>
#include <complex>
#define ll long long

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ms(m) memset(m,0,sizeof(m))

//#define C complex<int>
#define X real()
#define Y imag()

using namespace std;

const double PI = atan(1)*4;
#define inf 1e9
const int mod=1e9+7;

int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};

vector<int> ar[100009],ans;
int vis[100009],cyc=0;

void dfs(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!vis[x])
		{
			dfs(x);
		}
	}
	ans.pb(node);
}

void checkcyc(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!vis[x] && !cyc)
		{
			checkcyc(x);
		}
		else
			cyc=1;
	}
}

int main()
{

	#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int tt=1;
    //cin>>tt;

    while(tt--)
    {
    	int n,m;
    	cin>>n>>m;

    	int k[m];
    	forn(i,m)
    		cin>>k[i];

    	fori(i,1,n)
    	{
    		int x;
    		cin>>x;
    		forn(j,x)
    		{
    			int tm;
    			cin>>tm;
    			ar[i].pb(tm);
    		}
    	}

    	for(int i:k)
    	{
    		memset(vis,0,sizeof(vis));
    		checkcyc(i);
    	}

    	if(cyc)
    	{
    		cout<<-1;
    		continue;
    	}

    	memset(vis,0,sizeof(vis));
    	for(int i:k)
    	{
    		if(!vis[i])
    			dfs(i);
    	}

    	cout<<ans.size()<<"\n";
    	for(int x:ans) cout<<x<<" ";
   	}
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

    return 0;

}
                //              NOW IT'S TIME TO WAKE UP...


                                    //  IT'S NEVER TOO LATE...

#include <bits/stdc++.h>
#include <complex>
#define ll long long

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ms(m) memset(m,0,sizeof(m))

//#define C complex<int>
#define X real()
#define Y imag()

using namespace std;

const double PI = atan(1)*4;
#define inf 1e9
const int mod=1e9+7;

int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};

vector<int> ar[100009],ans;
int vis[100009];

void dfs(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!vis[x])
		{
			dfs(x);
		}
	}
	ans.pb(node);
}

int main()
{

	#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int tt=1;
    //cin>>tt;

    while(tt--)
    {
    	int n,m;
    	cin>>n>>m;

    	int k[m];
    	forn(i,m)
    		cin>>k[i];

    	fori(i,1,n)
    	{
    		int x;
    		cin>>x;
    		forn(j,x)
    		{
    			int tm;
    			cin>>tm;
    			ar[i].pb(tm);
    		}
    	}

    	for(int i:k)
    	{
    		if(!vis[i])
    			dfs(i);
    	}

    	cout<<ans.size()<<"\n";
    	for(int x:ans) cout<<x<<" ";
   	}
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

    return 0;

}
                //              NOW IT'S TIME TO WAKE UP...


                                    //  IT'S NEVER TOO LATE...

#include <bits/stdc++.h>
#include <complex>
#define ll long long

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ms(m) memset(m,0,sizeof(m))

//#define C complex<int>
#define X real()
#define Y imag()

using namespace std;

const double PI = atan(1)*4;
#define inf 1e9
const int mod=1e9+7;

int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};

vector<int> ar[100009];
int vis[100009];

void dfs(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!vis[x])
		{
			dfs(x);
		}
	}
	cout<<node<<" ";
}

int main()
{

	#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int tt=1;
    //cin>>tt;

    while(tt--)
    {
    	int n,m;
    	cin>>n>>m;

    	int k[m];
    	forn(i,m)
    		cin>>k[i];

    	fori(i,1,n)
    	{
    		int x;
    		cin>>x;
    		forn(j,x)
    		{
    			int tm;
    			cin>>tm;
    			ar[i].pb(tm);
    		}
    	}

    	for(int i:k)
    	{
    		if(!vis[i])
    			dfs(i);
    	}
   	}
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

    return 0;

}
                //              NOW IT'S TIME TO WAKE UP...


                                    //  IT'S NEVER TOO LATE...

#include <bits/stdc++.h>
#include <complex>
#define ll long long

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ms(m) memset(m,0,sizeof(m))

//#define C complex<int>
#define X real()
#define Y imag()

using namespace std;

const double PI = atan(1)*4;
#define inf 1e9
const int mod=1e9+7;

int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};

vector<int> ar[100009],ans;
int vis[100009],cyc=0,checked[100009];

void dfs(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!vis[x])
		{
			dfs(x);
		}
	}
	ans.pb(node);
}

void checkcyc(int node)
{
	vis[node] = 1;

	for(int x:ar[node])
	{
		if(!checked[x] && !cyc)
		{
			if(!vis[x])
			{
				checkcyc(x);
			}
			else
				cyc=1;
		}
	}
	checked[node] = 1;
}

int main()
{

	#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int tt=1;
    //cin>>tt;

    while(tt--)
    {
    	int n,m;
    	cin>>n>>m;

    	int k[m];
    	forn(i,m)
    		cin>>k[i];

    	fori(i,1,n)
    	{
    		int x;
    		cin>>x;
    		forn(j,x)
    		{
    			int tm;
    			cin>>tm;
    			ar[i].pb(tm);
    		}
    	}

    	for(int i:k)
    	{
    		memset(vis,0,sizeof(vis));
    		checkcyc(i);
    	}

    	if(cyc)
    	{
    		cout<<-1;
    		continue;
    	}

    	memset(vis,0,sizeof(vis));
    	for(int i:k)
    	{
    		if(!vis[i])
    			dfs(i);
    	}

    	cout<<ans.size()<<"\n";
    	for(int x:ans) cout<<x<<" ";
   	}
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

    return 0;

}
                //              NOW IT'S TIME TO WAKE UP...


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
const ll MOD=1000000007;
#define N (int)1e6+5

vector<int>v[N];
int color[N]={0};
bool cycle=false;
vector<int>ans;

void dfs(int curr)
{
	if(color[curr]==2)
	{
		return;
	}
	else if(color[curr]==1)
	{
		cycle=true;
		return;
	}
	else
	{
		color[curr]=1;
		for(int i=0;i<v[curr].size();i++)
		{
			dfs(v[curr][i]);
			if(cycle)return;
		}
		ans.pb(curr);
		color[curr]=2;
	}
}

int main()
{
	ios
	int n,k;
	cin>>n>>k;
	int req[k];
	for(int i=0;i<k;i++)
		cin>>req[i];
	for(int i=1;i<=n;i++)
	{
		int num;
		cin>>num;
		for(int j=0;j<num;j++)
		{
			int temp;
			cin>>temp;
			v[i].pb(temp);
		}
	}
	for(int i=0;i<k;i++)
	{
		if(color[req[i]])continue;
		dfs(req[i]);
		if(cycle)break;
	}
	if(cycle)cout<<-1<<nl;
	else
	{
		cout<<ans.size()<<nl;
		for(int i=0;i<ans.size();i++)
			cout<<ans[i]<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
const ll MOD=1000000007;
#define N (int)1e6+5

vector<int>v[N];
int color[N]={0};
bool cycle=false;
vector<int>ans;

void dfs(int curr)
{
	if(color[curr]==2)
	{
		return;
	}
	else if(color[curr]==1)
	{
		cycle=true;
		return;
	}
	else
	{
		color[curr]=1;
		for(int i=0;i<v[curr].size();i++)
		{
			dfs(v[curr][i]);
			if(cycle)return;
		}
		ans.pb(curr);
		color[curr]=2;
	}
}

int main()
{
	ios
	int n,k;
	cin>>n>>k;
	int req[k];
	for(int i=0;i<k;i++)
		cin>>req[i];
	for(int i=1;i<=n;i++)
	{
		int num;
		cin>>num;
		for(int j=0;j<num;j++)
		{
			int temp;
			cin>>temp;
			v[i].pb(temp);
		}
	}
	for(int i=0;i<k;i++)
	{
		if(color[req[i]])continue;
		dfs(req[i]);
		if(cycle)break;
	}
	if(cycle)cout<<-1<<nl;
	else
	{
		for(int i=0;i<ans.size();i++)
			cout<<ans[i]<<" ";
	}
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n,k;
vector<int> graph[100000];
vector<int> main_nodes;
vector<bool> visited;
vector<bool> rec_stack;

deque<int> order;
bool flag = true;
void dfs(int node){
    visited[node] = true;
    rec_stack[node] = true;
    for(int e : graph[node]){
        if(rec_stack[e]){
            flag = false;
            return;
        }
        if(!visited[e]){
            dfs(e);
        }
    }
    order.push_front(node);
    rec_stack[node] = false;
}
void dfs(){
    visited.assign(n, false);
    rec_stack.assign(n,false);
    for(int node : main_nodes){
        if(!flag){
            return;
        }
        if(!visited[node]){
            dfs(node);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    int v, t;
    for(int i=0;i<k;++i){
        cin >> v;
        main_nodes.push_back(v-1);
    }
    for(int i=0;i<n;++i){
        cin >> t;
        for(int j=0;j<t;++j){
            cin >> v;
            graph[i].push_back(v-1);
        }
    }
    /*for(int i=0;i<n;++i){
        cout << "node " << i << ":\n";
        for(int v : graph[i]){
            cout << "\t" << v << "\n";
        }
    }*/
    dfs();
    if(flag){
        cout << order.size() << "\n";
        while(!order.empty()){
            cout << order.back()+1 << " ";
            order.pop_back();
        }
    }else{
        cout << "-1";
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n,k;
vector<int> graph[100000];
vector<int> main_nodes;
vector<int> visited;

stack<int> order;
bool flag = true;
void dfs(int node,int comp){
    visited[node] = comp;
    order.push(node);
    for(int e : graph[node]){
        if(visited[e] == comp){
            flag = false;
            return;
        }
        if(!visited[e]){
            dfs(e,comp);
        }
    }
}
void dfs(){
    visited.assign(n, 0);
    int comp = 1;
    for(int node : main_nodes){
        if(!flag){
            return;
        }
        if(!visited[node]){
            dfs(node,comp++);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    int v, t;
    for(int i=0;i<k;++i){
        cin >> v;
        main_nodes.push_back(v-1);
    }
    for(int i=0;i<n;++i){
        cin >> t;
        for(int j=0;j<t;++j){
            cin >> v;
            graph[i].push_back(v-1);
        }
    }
    /*for(int i=0;i<n;++i){
        cout << "node " << i << ":\n";
        for(int v : graph[i]){
            cout << "\t" << v << "\n";
        }
    }*/
    dfs();
    if(flag){
        cout << order.size() << "\n";
        while(!order.empty()){
            cout << order.top()+1 << " ";
            order.pop();
        }
    }else{
        cout << "-1";
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n,k;
vector<int> graph[100000];
vector<int> main_nodes;
vector<bool> visited;
vector<bool> rec_stack;

stack<int> order;
bool flag = true;
void dfs(int node){
    visited[node] = true;
    order.push(node);
    rec_stack[node] = true;
    for(int e : graph[node]){
        if(rec_stack[e]){
            flag = false;
            return;
        }
        if(!visited[e]){
            dfs(e);
        }
    }
    rec_stack[node] = false;
}
void dfs(){
    visited.assign(n, false);
    rec_stack.assign(n,false);
    for(int node : main_nodes){
        if(!flag){
            return;
        }
        if(!visited[node]){
            dfs(node);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    int v, t;
    for(int i=0;i<k;++i){
        cin >> v;
        main_nodes.push_back(v-1);
    }
    for(int i=0;i<n;++i){
        cin >> t;
        for(int j=0;j<t;++j){
            cin >> v;
            graph[i].push_back(v-1);
        }
    }
    /*for(int i=0;i<n;++i){
        cout << "node " << i << ":\n";
        for(int v : graph[i]){
            cout << "\t" << v << "\n";
        }
    }*/
    dfs();
    if(flag){
        cout << order.size() << "\n";
        while(!order.empty()){
            cout << order.top()+1 << " ";
            order.pop();
        }
    }else{
        cout << "-1";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define double long double

const double PI = 3.1415926;
const ll INF_LL = 1e18+7;
const double EPS = 1e-18;
const int INF_int = 1e9+7;
const int maxn = 1e5+10;

int n, k, t = 0;
bool sosatb = false;
vector<vector <int>> g;
vector <int> used;
vector <int> check;
vector <int> tout;
set <pair <int, int>> ans;

void dfs(int v, int st)
{
    used[v] = 1;
    for (int to : g[v])
    {
        if (used[to])
        {
            if (to == st) sosatb = true;
            continue;
        }
        dfs(to, st);
    }
    tout[v] = ++t;
}

void dfs2(int v)
{
    used[v] = 1;
    ans.insert({tout[v], v});
    for (int to : g[v])
    {
        if (used[to]) continue;
        dfs2(to);
    }
}

int32_t main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//    freopen("network.in","r", stdin);
//    freopen("network.out","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i)
    {
        cin >> x;
        check.pb(--x);
    }
    g.assign(n, vector <int> (0));
    used.assign(n, 0);
    tout.assign(n, 0);
    for (int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        for (int j = 0, x; j < temp; ++j)
        {
            cin >> x; x--;
            g[i].pb(x);
        }
    }
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs(check[i], check[i]);
    }
    if (sosatb)
    {
        cout << -1;
        return 0;
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
        if (used[check[i]] == 0) dfs2(check[i]);
    cout << ans.size() << endl;
    for (auto it : ans)
        cout << it.S+1 << ' ';
    return 0;
}

/* Thu Sep 17 2020 21:08:15 GMT+0300 (Москва, стандартное время) */


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define double long double

const double PI = 3.1415926;
const ll INF_LL = 1e18+7;
const double EPS = 1e-18;
const int INF_int = 1e9+7;
const int maxn = 1e5+10;

int n, k, t = 0;
bool sosatb = false;
vector<vector <int>> g;
vector <int> used;
vector <int> check;
vector <int> tout;
set <pair <int, int>> ans;

void dfs(int v, int st)
{
    used[v] = 1;
    for (int to : g[v])
    {
        if (used[to] == 1)
        {
            sosatb = true;
            continue;
        }
        if (used[v] == 2) continue;
        dfs(to, st);
    }
    used[v] = 2;
    tout[v] = ++t;
}

void dfs2(int v)
{
    used[v] = 1;
    ans.insert({tout[v], v});
    for (int to : g[v])
    {
        if (used[to]) continue;
        dfs2(to);
    }
}

int32_t main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//    freopen("network.in","r", stdin);
//    freopen("network.out","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i)
    {
        cin >> x;
        check.pb(--x);
    }
    g.assign(n, vector <int> (0));
    used.assign(n, 0);
    tout.assign(n, 0);
    for (int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        for (int j = 0, x; j < temp; ++j)
        {
            cin >> x; x--;
            g[i].pb(x);
        }
    }
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs(check[i], check[i]);
    }
    if (sosatb)
    {
        cout << -1;
        return 0;
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
        if (used[check[i]] == 0) dfs2(check[i]);
    cout << ans.size() << endl;
    for (auto it : ans)
        cout << it.S+1 << ' ';
    return 0;
}

/* Thu Sep 17 2020 21:08:15 GMT+0300 (Москва, стандартное время) */

/* Thu Sep 17 2020 22:00:52 GMT+0300 (Москва, стандартное время) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> c;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    c.push_back(v);
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";

    return 0;
}

/* Tue Jan 28 2020 22:26:20 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> c;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    c.push_back(v);
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << c.size() << "\n";
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";

    return 0;
}

/* Tue Jan 28 2020 22:31:01 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> c;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    c.push_back(v);
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << c.size() << "\n";
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";

    return 0;
}

/* Tue Jan 28 2020 22:39:23 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
map<int, int> tout;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    t++;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    tout[t] = v;
    t++;
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << tout.size() << endl;
    for(auto it : tout) {
        cout << it.second << " ";
    }
    cout << endl;

    return 0;
}

/* Tue Jan 28 2020 17:01:05 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define double long double

const double PI = 3.1415926;
const ll INF_LL = 1e18+7;
const double EPS = 1e-18;
const int INF_int = 1e9+7;
const int maxn = 1e5+10;

int n, k, t = 0;
bool sosatb = false;
vector<vector <int>> g;
vector <int> used;
vector <int> check;
vector <int> tout;
set <pair <int, int>> ans;

void dfs(int v, int st)
{
    used[v] = 1;
    for (int to : g[v])
    {
        if (used[to])
        {
            if (to == st) sosatb = true;
            continue;
        }
        dfs(to, st);
    }
    tout[v] = ++t;
}

void dfs2(int v)
{
    used[v] = 1;
    ans.insert({tout[v], v});
    for (int to : g[v])
    {
        if (used[to]) continue;
        dfs2(to);
    }
}

int32_t main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//    freopen("network.in","r", stdin);
//    freopen("network.out","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i)
    {
        cin >> x;
        check.pb(--x);
    }
    g.assign(n, vector <int> (0));
    used.assign(n, 0);
    tout.assign(n, 0);
    for (int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        for (int j = 0, x; j < temp; ++j)
        {
            cin >> x; x--;
            g[i].pb(x);
        }
    }
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs(check[i], check[i]);
    }
    if (sosatb)
    {
        cout << -1;
        return 0;
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
        if (used[check[i]] == 0) dfs2(check[i]);
    cout << ans.size() << endl;
    for (auto it : ans)
        cout << it.S+1 << ' ';
    return 0;
}

/* Thu Sep 17 2020 21:03:33 GMT+0300 (Москва, стандартное время) */


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <tuple>
#include <iostream>
#include <random>
#include <iterator>
#include <list>
#include <iomanip>
#include <random>
#include <complex>
#include <deque>
#include <numeric>

using namespace std;

#define ACCEPTED return 0;
#define pause system("pause")
#define optimize ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define mas(x) (x), (x) + n
#define sz(x) (x).size()
#define sc(x) scanf("%d", &(x))
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define scnaf scanf
#define scafn scanf

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef stack<int> si;
typedef queue<int> aye;
typedef vector<bool> vb;
typedef vector<pii> vpii;

const int maxn = (int)1e5 + 7;
const double eps = 1e-7;
const ld pi = 3.14159265358979323846;
const ld e = 2.71828182845904523536;
const ll inf = (ll)1e18;
const int mod = (int)1e9 + 7;

int n, m;
vi used;
vvi g;
int tglobal = 0;
vi tout;
bool prof[maxn];
bool ka = false;

void dfs(int v)
{
	used[v] = 1;

	for(int to : g[v])
	{
		if (used[to] == 0)
		{
			dfs(to);
			tglobal++;
		}
		else
		{
			if (used[to] == 1)
				ka = true;
		}
	}

	if (m > 0)
	{
		tout.pb(v + 1);
		if (prof[v + 1])
			m--;
	}
	used[v] = 2;
	tglobal++;
}

void solve()
{
	cin >> n >> m;
	ka = m ? 0 : 1;
	g.resize(n);
	used.resize(n);

	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		prof[a] = true;
	}
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		for (int j = 0; j < a; j++)
		{
			int b;
			cin >> b;
			g[i].pb(b - 1);
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (!used[i])
			dfs(i);
	}

	if (ka)
	{
		cout << -1;
	}
	else
	{
		cout << sz(tout) << "\n";
	}

	for (int i = 0; i < sz(tout) && !ka; i++)
	{
		cout << tout[i] << " ";
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	solve();

	ACCEPTED
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> res;
bool cycle = false;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
            res.pb(to);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
            res.pb(courses[i]);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << res.size() << endl;
    for(int i : res) {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

/* Tue Jan 28 2020 15:03:42 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define pld pair<ll, double>
#define pb push_back
#define forn(tt) for(ll i = 0; i < tt; ++i)
#define sn second
#define fr first

#pragma GCC optimize("O3")

template<typename T>
void dev(T dt) {
	cout << "DEV: " << dt << "\n";
}

vector<vector<ll>> g;
vector<ll> used, tin, tout, ans;
vector<vector<ll>> deps;
map<ll, bool> solved;

ll k = 0;

void dfs(ll v) {
	used[v] = 1;
	ll cnt = 0;
	for(auto x : deps[v]) {
		if(solved[x]) {
			cnt++;
		}
		if(!used[x]) {
			dfs(x);
			if(solved[x]) {
				cnt++;
			}

		}

	}
	if(cnt == deps[v].size()) {
		solved[v] = 1;
		ans.pb(v);
	}
}

ll solve() {
	ll n, k;
	cin >> n >> k;
	g.resize(n), used.resize(n), tin.resize(n), tout.resize(n);
	vector<ll> mn(k);
	for(ll i = 0; i < k; ++i) {
		cin >> mn[i];
		--mn[i];
	}
	deps.resize(n);
	for(ll i = 0; i < n; ++i) {
		ll t;
		cin >> t;
		for(ll j = 0; j < t; ++j) {
			ll x;
			cin >> x;
			deps[i].pb(x - 1);
		}
	}
	for(ll i = 0; i < k; ++i) {
		if(!solved[mn[i]] && !used[mn[i]]) {
			dfs(mn[i]);
			if(!solved[mn[i]]) {
				cout << -1;
				return 0;
			}
		}
	}
	cout << ans.size() << "\n";
	for(ll i = 0; i < ans.size(); ++i) {
		cout << ans[i] + 1 << " ";
	}
	return 0;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	return (int)solve();
}

/* Tue Jan 28 2020 22:05:24 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <tuple>
#include <iostream>
#include <random>
#include <iterator>
#include <list>
#include <iomanip>
#include <random>
#include <complex>
#include <deque>
#include <numeric>

using namespace std;

#define ACCEPTED return 0;
#define pause system("pause")
#define optimize ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define mas(x) (x), (x) + n
#define sz(x) (x).size()
#define sc(x) scanf("%d", &(x))
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define scnaf scanf
#define scafn scanf

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef stack<int> si;
typedef queue<int> aye;
typedef vector<bool> vb;
typedef vector<pii> vpii;

const int maxn = (int)1e5 + 7;
const double eps = 1e-7;
const ld pi = 3.14159265358979323846;
const ld e = 2.71828182845904523536;
const ll inf = (ll)1e18;
const int mod = (int)1e9 + 7;

int n, m;
vi used;
vvi g;
int tglobal = 0;
vi tout;
bool prof[maxn];
bool ka = false;

void dfs(int v)
{
	used[v] = 1;

	for(int to : g[v])
	{
		if (used[to] == 0)
		{
			dfs(to);
			tglobal++;
		}
		else
		{
			if (used[to] == 1)
				ka = true;
		}
	}

	if (m > 0)
	{
		tout.pb(v + 1);
		if (prof[v + 1])
			m--;
	}
	used[v] = 2;
	tglobal++;
}

void solve()
{
	cin >> n >> m;
	g.resize(n);
	used.resize(n);

	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		prof[a] = true;
	}
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		for (int j = 0; j < a; j++)
		{
			int b;
			cin >> b;
			g[i].pb(b - 1);
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (!used[i])
			dfs(i);
	}

	if (ka)
	{
		cout << -1;
	}
	else
	{
		cout << sz(tout) << "\n";
	}

	for (int i = 0; i < sz(tout) && !ka; i++)
	{
		cout << tout[i] << " ";
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	solve();

	ACCEPTED
}
/* Tue Jan 28 2020 21:07:36 GMT+0300 (MSK) */


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long int iint;
const iint Mod = 1000000007;

int n;
vector<vector<int>> gr(1e5 + 1);
vector<int> used(1e5 + 1), ans, us(1e5 + 1);
map<int, int> use;
bool f = 0;

void dfs(int v, int last) {
	used[v] = 1;
	for (auto i : gr[v]) {
		if (!used[i]) {
			dfs(i, v);
		} else {
			if (i != last && last != -1) {
				f = 1;
			}
		}
	}
	ans.push_back(v);
}

void mark(int v) {
	us[v] = 1;
	for (auto i : gr[v]) {
		if (!us[i]) {
			mark(i);
		}
	}
}

int Solve() {
	int k;
	cin >> n >> k;
	vector<int> need(k);
	for (int i = -1; ++i < k;) {
		cin >> need[i];
	}
	for (int i = 0; ++i <= n;) {
		int t; cin >> t;
		for (int j = -1; ++j < t;) {
			int x; cin >> x;
			gr[i].push_back(x);
		}
	}
	for (auto i : need) {
		use[i] = 1;
		mark(i);
	}

	for (int i = 0; ++i <= n;) {
		if (!us[i]) {
			gr[i].clear();
		}
	}

	for (int i = 0; ++i <= n;) {
		if (!used[i] && (gr[i].size() != 0 || use[i] == 1)) {
			dfs(i, -1);
		}
	}
	if (f) {
		cout << "-1\n";
		return 0;
	}
	cout << ans.size() << '\n';
	for (auto i : ans) {
		cout << i << " ";
	}
	cout << '\n';
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
   cout.precision(22);
   //freopen("input.txt", "r", stdin), freopen("linear.out", "w", stdout);
	return Solve();
}

/* Tue Jan 28 2020 19:56:42 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> c;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(used[to] == 2)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    c.push_back(v);
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << c.size() << "\n";
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";

    return 0;
}

/* Tue Jan 28 2020 22:45:33 GMT+0300 (MSK) */


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
bool isPrime(long long int x) {
	if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
	for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;
}

#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"
//#define LONG_LONG_MAX  9223372036854775807
//#define LONG_LONG_MIN   -9223372036854775807
//#define max3(a, b, c) max(a, max(b, c))
//#define min3(a, b, c) min(a, min(b, c))
//#define PI 3.14159265
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}

const int INF = 1e18;

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}
int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

bool bigger(string a, string b) {
	if (a.size() == b.size())
		return a > b;
	return a.size() > b.size();
}

string max_str(string a, string b) {
	if (bigger(a, b))
		return a;
	return b;
}
string min_str(string a, string b) {
	if (bigger(a, b))
		return b;
	return a;
}

vector<int> strtovec(string s) {
	vector<int> v;
	for (int i = 0; i < s.size(); i++) {
		v.push_back((int)(s[i] - 48));
	}
	return v;
}

string vectostr(vector<int> a) {
	string s;
	for (int i = 0; i < a.size(); i++) {
		s += to_string(a[i]);
	}
	return s;
}

vector<vector<int>> mult(vector<vector<int>> p, vector<vector<int>> f, const int n, const int mod) {
	vector<vector<int>> d;
	d = p;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			p[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				p[i][j] = (p[i][j] + (d[i][k] * f[k][j])) % mod;
			}
		}
	}
	return p;
}

vector<vector<int>> quickpow(vector<vector<int>> p, int s, const int n, const int m) {
	if (s == 0) {
		vector<vector<int>> tmp(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			tmp[i][i] = 1;
		}
		return tmp;
	}
	if (s % 2 == 1) {
		return mult(quickpow(p, s - 1, n, m), p, n, m);
	}
	else {
		vector<vector<int>> temp(n, vector<int>(n, 0));
		temp = quickpow(p, s / 2, n, m);
		return mult(temp, temp, n, m);
	}
}

int const maxn = 100005;
int tree[maxn * 4];
int sz;

void build(vector<int> a) {
	sz = 1;
	int n = a.size();
	while (sz <= n)
		sz <<= 1;
	for (int i = 0; i < n; ++i) {
		tree[i + sz] = a[i];
	}
	for (int i = sz - 1; i > 0; --i)
		tree[i] = tree[2 * i] + tree[2 * i + 1];
}

void upd(int idx, int val) {
	for (tree[idx += sz] = val; idx > 1; idx >>= 1)
		tree[idx >> 1] = max(tree[idx], tree[idx ^ 1]);
}

int get(int l, int r) {
	int res = 0;
	for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)
			res = res + tree[l++];
		if (~r & 1)
			res = res + tree[r--];
	}
	return res;
}

bool comp1(pair<int, int> p1, pair<int, int> p2) {
	if (p1.first == p2.first)
		return p1.second < p2.second;
	return p1.first < p2.first;
}
bool comp2(pair<int, int> p1, pair<int, int>  p2) {
	if (p1.second == p2.second)
		return p1.first < p2.first;
	return p1.second < p2.second;
}

string long_mult(string num1, string num2)
{
	int len1 = num1.size();
	int len2 = num2.size();
	if (len1 == 0 || len2 == 0)
		return "0";

	// will keep the result number in vector
	// in reverse order
	vector<int> result(len1 + len2, 0);

	// Below two indexes are used to find positions
	// in result.
	int i_n1 = 0;
	int i_n2 = 0;

	// Go from right to left in num1
	for (int i = len1 - 1; i >= 0; i--)
	{
		int carry = 0;
		int n1 = num1[i] - '0';

		// To shift position to left after every
		// multiplication of a digit in num2
		i_n2 = 0;

		// Go from right to left in num2
		for (int j = len2 - 1; j >= 0; j--)
		{
			// Take current digit of second number
			int n2 = num2[j] - '0';

			// Multiply with current digit of first number
			// and add result to previously stored result
			// at current position.
			int sum = n1 * n2 + result[i_n1 + i_n2] + carry;

			// Carry for next iteration
			carry = sum / 10;

			// Store result
			result[i_n1 + i_n2] = sum % 10;

			i_n2++;
		}

		// store carry in next cell
		if (carry > 0)
			result[i_n1 + i_n2] += carry;

		// To shift position to left after every
		// multiplication of a digit in num1.
		i_n1++;
	}

	// ignore '0's from the right
	int i = result.size() - 1;
	while (i >= 0 && result[i] == 0)
		i--;

	// If all were '0's - means either both or
	// one of num1 or num2 were '0'
	if (i == -1)
		return "0";

	// generate the result string
	string s = "";

	while (i >= 0)
		s += std::to_string(result[i--]);

	return s;
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

const int modulo = 1000000000000007;

bool comp(pair<int, int> p1, pair<int, int> p2) {
	if (p1.first == p2.first)
		return p1.second < p2.second;
	return p1.first < p2.first;
}

string long_sum(string str1, string str2)
{
	// Before proceeding further, make sure length
	// of str2 is larger.
	if (str1.length() > str2.length())
		swap(str1, str2);

	// Take an empty string for storing result
	string str = "";

	// Calculate length of both string
	int n1 = str1.length(), n2 = str2.length();

	// Reverse both of strings
	reverse(str1.begin(), str1.end());
	reverse(str2.begin(), str2.end());

	int carry = 0;
	for (int i = 0; i < n1; i++)
	{
		// Do school mathematics, compute sum of
		// current digits and carry
		int sum = ((str1[i] - '0') + (str2[i] - '0') + carry);
		str.push_back(sum % 10 + '0');

		// Calculate carry for next step
		carry = sum / 10;
	}

	// Add remaining digits of larger number
	for (int i = n1; i < n2; i++)
	{
		int sum = ((str2[i] - '0') + carry);
		str.push_back(sum % 10 + '0');
		carry = sum / 10;
	}

	// Add remaining carry
	if (carry)
		str.push_back(carry + '0');

	// reverse resultant string
	reverse(str.begin(), str.end());

	return str;
}

vector<int> used;
vector<vector<int>> g;
vector<int> ms;
vector<int> ans;
vector<int> ord;
int c = 0;

void dfs(int v) {
	if (used[v] == 0) {
		used[v] = 1;
		for (int to : g[v])
			dfs(to);
		used[v] = 2;
		ord.push_back(v);
	}
	else if (used[v] == 1)
		c = 1;
}

int32_t main() {
	boostIO();
	int n = 0, m, answ = 0, k = 0;
	cin >> n >> k;
	ms.resize(k, 0);
	fori(k) {
		cin >> ms[i];
		ms[i]--;
	}
	sort(ms.begin(), ms.end());
	used.resize(n, 0);
	g.resize(n);
	fori(n) {
		cin >> m;
		forj(m) {
			int u;
			cin >> u;
			u--;
			g[i].push_back(u);
		}
	}
	fori(k) {
			dfs(ms[i]);
	}
	if (c)
		cout << -1;
	else {
		cout << ord.size() << endl;
		fori(ord.size())
			cout << ord[i] + 1 << " ";
	}
}
/* Tue Jan 28 2020 22:00:40 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define double long double

const double PI = 3.1415926;
const ll INF_LL = 1e18+7;
const double EPS = 1e-18;
const int INF_int = 1e9+7;
const int maxn = 1e5+10;

int n, k, t = 0;
bool sosatb = false;
vector<vector <int>> g;
vector <int> used;
vector <int> check;
vector <int> tout;
set <pair <int, int>> ans;

void dfs(int v)
{
    used[v] = 1;
    for (int to : g[v])
    {
        if (used[to] == 1)
        {
            sosatb = true;
            continue;
        }
        if (used[to] == 2) continue;
        dfs(to);
    }
    used[v] = 2;
    tout[v] = ++t;
}

void dfs2(int v)
{
    used[v] = 1;
    ans.insert({tout[v], v});
    for (int to : g[v])
    {
        if (used[to]) continue;
        dfs2(to);
    }
}

int32_t main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//    freopen("network.in","r", stdin);
//    freopen("network.out","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i)
    {
        cin >> x;
        check.pb(--x);
    }
    g.assign(n, vector <int> (0));
    used.assign(n, 0);
    tout.assign(n, 0);
    for (int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        for (int j = 0, x; j < temp; ++j)
        {
            cin >> x; x--;
            g[i].pb(x);
        }
    }
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs(check[i]);
    }
    if (sosatb)
    {
        cout << -1;
        return 0;
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
        if (used[check[i]] == 0) dfs2(check[i]);
    cout << ans.size() << endl;
    for (auto it : ans)
        cout << it.S+1 << ' ';
    return 0;
}

/* Thu Sep 17 2020 21:08:15 GMT+0300 (Москва, стандартное время) */

/* Thu Sep 17 2020 22:06:55 GMT+0300 (Москва, стандартное время) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
vector<int> c;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    for(int to : g[v]) {
        if(to == p)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    c.push_back(v);
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << c.size();
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";

    return 0;
}

/* Tue Jan 28 2020 22:30:08 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <tuple>
#include <iostream>
#include <random>
#include <iterator>
#include <list>
#include <iomanip>
#include <random>
#include <complex>
#include <deque>
#include <numeric>

using namespace std;

#define ACCEPTED return 0;
#define pause system("pause")
#define optimize ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define mas(x) (x), (x) + n
#define sz(x) (x).size()
#define sc(x) scanf("%d", &(x))
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define scnaf scanf
#define scafn scanf

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef stack<int> si;
typedef queue<int> aye;
typedef vector<bool> vb;
typedef vector<pii> vpii;

const int maxn = (int)1e5 + 7;
const double eps = 1e-7;
const ld pi = 3.14159265358979323846;
const ld e = 2.71828182845904523536;
const ll inf = (ll)1e18;
const int mod = (int)1e9 + 7;

int n, m;
vi used;
vvi g;
int tglobal = 0;
vi tout;
bool prof[maxn];
bool ka = false, exitf = false;

void dfs(int v)
{
	used[v] = 1;

	for(int to : g[v])
	{
		if (used[to] == 0)
		{
			dfs(to);
			tglobal++;
		}
		else
		{
			if (used[to] == 1)
				ka = true;
		}
	}

	if (m > 0)
	{
		tout.pb(v + 1);
		if (prof[v + 1])
			m--;

		if (!m && !ka && !exitf)
		{
			cout << sz(tout) << "\n";

			for (int i = 0; i < sz(tout) && !ka; i++)
			{
				cout << tout[i] << " ";
			}
			exitf = true;
		}
	}
	used[v] = 2;
	tglobal++;
}

void solve()
{
	cin >> n >> m;
	ka = m ? 0 : 1;
	g.resize(n);
	used.resize(n);

	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		prof[a] = true;
	}

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		for (int j = 0; j < a; j++)
		{
			int b;
			cin >> b;
			g[i].pb(b - 1);
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (!used[i])
			dfs(i);
	}

	if (ka && !exitf)
	{
		cout << -1;
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	solve();

	ACCEPTED
}
/* Tue Jan 28 2020 21:39:16 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<pii> tout;
unordered_set<int> courses;
int t = 1;
bool cycle = false;
int res = 0;

void dfs(int v, int p) {
    used[v] = 1;
    t++;
    for(int to : g[v]) {
        if(p == to)
            continue;
        if(used[to] == 0) {
            dfs(to, v);
        }
        else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    tout[v - 1] = mp(v, t);
    t++;
}

int dfs2(int v) {
    used[v] = 1;
    int take = 0;
    int cur = 0;
    if(courses.find(v) != courses.end()) {
        used[v] = 2;
        take = 1;
        courses.erase(v);
    }
    for(int to : g[v]) {
        if(used[to] == 0) {
            int val = dfs2(to);
            if(val != 0) {
                used[v] = 2;
                take = 1;
            }
            cur += val;
        }
        else if(used[to] == 2) {
            used[v] = 2;
            take = 1;
        }
    }
    return cur + take;
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);
    tout.resize(n);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.insert(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[a].pb(i);
        }
    }

    for(int i = 1; i <= n; i++) {
        if(used[i] == 0) {
            dfs(i, 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    sort(tout.begin(), tout.end(), [](pii a, pii b) -> bool {return a.second > b.second;});

    used.assign(n + 1, 0);
    for(int i = 0; i < tout.size(); i++) {
        int v = tout[i].first;
        if(used[v] == 0)
            res += dfs2(v);
    }

    cout << res << endl;

    for(int i = 0; i < tout.size(); i++) {
        int v = tout[i].first;
        if(used[v] == 2) {
            cout << v << " ";
        }
    }

    cout << endl;

    return 0;
}

/* Tue Jan 28 2020 13:45:31 GMT+0300 (MSK) */


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long int iint;
const iint Mod = 1000000007;

vector<vector<int>> gr(1e5 + 1);
vector<int> used(1e5 + 1, 0), ans, u(1e5 + 1, 0), tin(1e5 + 1, 0), tout(1e5 + 1, 0);
map<int, int> mp;

bool f = 1;

void dfs(int v) {
	used[v] = 1;
	tin[v] = 1;
	for (auto i : gr[v]) {
		if (!used[i]) {
			dfs(i);
		} else {
			if (!tout[i]) {
				f = 0;
			}
		}
	}
	tout[v] = 1;
	ans.push_back(v);
}

void dfs1(int v) {
	u[v] = 1;
	for (auto i : gr[v]) {
		if (!u[i]) {
			dfs1(i);
		}
	}
}

int Solve() {
	int n, k;
	cin >> n >> k;
	for (int i = -1; ++i < k;) {
		int x; cin >> x;
		mp[x] = 1;
	}

	for (int i = 0; ++i <= n;) {
		int t; cin >> t;
		for (int j = -1; ++j < t;) {
			int x; cin >> x;
			gr[i].push_back(x);
		}
	}

	for (auto i : mp) {
		if (!u[i.first]) {
			dfs1(i.first);
		}
	}
	for (int i = 0; ++i <= n;) {
		if (!u[i]) {
			gr[i].clear();
		}
	}

	for (int i = 0; ++i <= n;) {
		if (!used[i] && (gr[i].size() != 0 || mp[i])) {
			dfs(i);
		}
	}
	if (f) {
		cout << ans.size() << '\n';
		for (auto i : ans) {
			cout << i << " ";
		}
		cout << '\n';
	} else {
		cout << "-1\n";
	}

	return 0;
}

int main() {
	/*ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
  */ cout.precision(22);
   //freopen("input.txt", "r", stdin), freopen("linear.out", "w", stdout);
	return Solve();
}

/* Wed Jan 29 2020 00:25:31 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pld pair<ld, ld>
#define mp make_pair

using namespace std;

vector<vector<int>> g;
vector<int> used;
vector<int> courses;
map<int, int> tout;
bool cycle = false;
int t = 1;

void dfs(int v, int p) {
    used[v] = 1;
    t++;
    for(int to : g[v]) {
       // if(to == p)
       //     continue;
        if(used[to] == 0) {
            dfs(to, v);
        } else if(used[to] == 1) {
            cycle = true;
        }
    }
    used[v] = 2;
    tout[t] = v;
    t++;
}

int main() {
    int n, m, a, b, k;
    cin >> n >> k;
    g.resize(n + 1);
    used.assign(n + 1, 0);

    for(int i = 0;  i < k; i++) {
        cin >> a;
        courses.pb(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> b;
        for(int j = 0; j < b; j++) {
            cin >> a;
            g[i].pb(a);
        }
    }

    for(int i = 0; i < courses.size(); i++) {
        if(used[courses[i]] == 0) {
            dfs(courses[i], 0);
        }
    }

    if(cycle) {
        cout << -1 << endl;
        return 0;
    }

    cout << tout.size() << endl;
    for(auto it : tout) {
        cout << it.second << " ";
    }
    cout << endl;

    return 0;
}
/* Wed Jan 29 2020 08:51:16 GMT+0300 (MSK) */


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long int iint;
const iint Mod = 1000000007;

int n;
vector<vector<int>> gr(1e5 + 1);
vector<int> used(1e5 + 1), ans, us(1e5 + 1);
map<int, int> use;
bool f = 0;

void dfs(int v, int last) {
	used[v] = 1;
	for (auto i : gr[v]) {
		if (!used[i]) {
			dfs(i, v);
		} else {
			if (i != last) {
				f = 1;
			}
		}
	}
	ans.push_back(v);
}

void mark(int v) {
	us[v] = 1;
	for (auto i : gr[v]) {
		if (!us[i]) {
			mark(i);
		}
	}
}

int Solve() {
	int k;
	cin >> n >> k;
	vector<int> need(k);
	for (int i = -1; ++i < k;) {
		cin >> need[i];
	}
	for (int i = 0; ++i <= n;) {
		int t; cin >> t;
		for (int j = -1; ++j < t;) {
			int x; cin >> x;
			gr[i].push_back(x);
		}
	}
	for (auto i : need) {
		use[i] = 1;
		mark(i);
	}

	for (int i = 0; ++i <= n;) {
		if (!us[i]) {
			gr[i].clear();
		}
	}

	for (int i = 0; ++i <= n;) {
		if (!used[i] && (gr[i].size() != 0 || use[i] == 1)) {
			dfs(i, -1);
		}
	}
	if (f) {
		cout << "-1\n";
		return 0;
	}
	cout << ans.size() << '\n';
	for (auto i : ans) {
		cout << i << " ";
	}
	cout << '\n';
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
   cout.precision(22);
   //freopen("input.txt", "r", stdin), freopen("linear.out", "w", stdout);
	return Solve();
}

/* Tue Jan 28 2020 19:51:01 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define double long double

const double PI = 3.1415926;
const ll INF_LL = 1e18+7;
const double EPS = 1e-18;
const int INF_int = 1e9+7;
const int maxn = 1e5+10;

int n, k, t = 0;
bool sosatb = false;
vector<vector <int>> g;
vector <int> used;
vector <int> check;
vector <int> tout;
set <pair <int, int>> ans;

void dfs(int v, int st = 1)
{
    used[v] = st;
    for (int to : g[v])
    {
        if (used[to] == st)
        {
            sosatb = true;
            continue;
        }
        dfs(to, st);
    }
}

void dfs0(int v)
{
    used[v] = 1;
    for (int to : g[v])
    {   if (used[to]) continue;
        dfs0(to);
    }
    tout[v] = t++;
}

void dfs2(int v)
{
    used[v] = 1;
    ans.insert({tout[v], v});
    for (int to : g[v])
    {
        if (used[to]) continue;
        dfs2(to);
    }
}

int32_t main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//    freopen("network.in","r", stdin);
//    freopen("network.out","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i)
    {
        cin >> x;
        check.pb(--x);
    }
    g.assign(n, vector <int> (0));
    used.assign(n, 0);
    tout.assign(n, 0);
    for (int i = 0; i < n; ++i)
    {
        int temp; cin >> temp;
        for (int j = 0, x; j < temp; ++j)
        {
            cin >> x; x--;
            g[i].pb(x);
        }
    }
    int temp = 1;
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs(check[i], temp++);
    }
    if (sosatb)
    {
        cout << -1;
        return 0;
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
    {
        if (used[check[i]] == 0) dfs0(check[i]);
    }
    fill(all(used), 0);
    for (int i = 0; i < k; ++i)
        if (used[check[i]] == 0) dfs2(check[i]);
    cout << ans.size() << endl;
    for (auto it : ans)
        cout << it.S+1 << ' ';
    return 0;
}

/* Thu Sep 17 2020 21:35:00 GMT+0300 (Москва, стандартное время) */


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  for (int i = 0; i < k; i++)
    cin >> a[i];
  vector<vector<int>> adj(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int course;
      cin >> course;
      --course;
      adj[i].emplace_back(course);
    }
  }
  vector<int> col(n);
  function<bool(int)> cycle = [&](int u) {
    col[u] = 2;
    for (int to : adj[u]) {
      if (col[to] == 2)
        return true;
      if (cycle(to))
        return true;
    }
    col[u] = 1;
    return false;
  };
  for (int i = 0; i < k; i++) {
    --a[i];
    if (col[a[i]] != 1 && cycle(a[i])) {
      cout << "-1\n";
      return 0;
    }
  }
  vector<bool> vis(n);
  vector<int> res;
  function<void(int)> dfs = [&](int u) {
    vis[u] = true;
    for (int to : adj[u]) if (!vis[to]) {
      dfs(to);
    }
    res.emplace_back(u);

  };
  for (int i = 0; i < k; i++) {
    // --a[i];
    if (!vis[a[i]]) {
      dfs(a[i]);
    }
  }
  cout << res.size() << '\n';
  for (int p : res)
    cout << p + 1 << ' ';
  cout << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  for (int i = 0; i < k; i++)
    cin >> a[i];
  vector<vector<int>> adj(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int course;
      cin >> course;
      --course;
      adj[i].emplace_back(course);
    }
  }
  vector<int> col(n);
  function<bool(int)> cycle = [&](int u) {
    col[u] = 2;
    for (int to : adj[u]) {
      if (col[to] == 2)
        return true;
      if (cycle(to))
        return true;
    }
    col[u] = 1;
    return false;
  };
  for (int i = 0; i < k; i++) {
    --a[i];
    if (cycle(a[i])) {
      cout << "-1\n";
      return 0;
    }
  }
  vector<bool> vis(n);
  vector<int> res;
  function<void(int)> dfs = [&](int u) {
    vis[u] = true;
    for (int to : adj[u]) if (!vis[to]) {
      dfs(to);
    }
    res.emplace_back(u);

  };
  for (int i = 0; i < k; i++) {
    // --a[i];
    if (!vis[a[i]]) {
      dfs(a[i]);
    }
  }
  cout << res.size() << '\n';
  for (int p : res)
    cout << p + 1 << ' ';
  cout << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  for (int i = 0; i < k; i++)
    cin >> a[i];
  vector<vector<int>> adj(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int course;
      cin >> course;
      --course;
      adj[i].emplace_back(course);
    }
  }
  vector<int> col(n);
  function<bool(int)> cycle = [&](int u) {
    col[u] = 2;
    for (int to : adj[u]) {
      if (col[to] == 2)
        return true;
      if (cycle(to))
        return true;
    }
    col[u] = 1;
    return false;
  };
  for (int i = 0; i < k; i++) {
    --a[i];
    if (cycle(a[i])) {
      cout << "-1\n";
      return 0;
    }
  }
  assert(false);
  vector<bool> vis(n);
  vector<int> res;
  function<void(int)> dfs = [&](int u) {
    vis[u] = true;
    for (int to : adj[u]) if (!vis[to]) {
      dfs(to);
    }
    res.emplace_back(u);

  };
  for (int i = 0; i < k; i++) {
    // --a[i];
    if (!vis[a[i]]) {
      dfs(a[i]);
    }
  }
  cout << res.size() << '\n';
  for (int p : res)
    cout << p + 1 << ' ';
  cout << '\n';
  return 0;
}