#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
long long a[MAXN], b[MAXN];
long long n,y , z, t, m,f, x , d = 1, c, g[MAXN], k;
vector <int> v[MAXN], h;
bool mark[MAXN],mark1[MAXN], io = false;
//char g;
long long dfs (long long x)
{
//	h.push_back(s);
	g[x] = 1;
	for (int i = 0; i < v[x].size(); i++)
	{

		if (g[v[x][i]] == 0)
		{
			k = dfs(v[x][i]);
			if (k == -1)
			{
				return -1;
			}
			if (g[v[x][i]] == 2)
			{
				b[d] = v[x][i];
				d++;
			}

		}
		else if (g[v[x][i]] == 1)
		{
			return -1;
		}
	}
	g[x] = 2;

}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		for (int j = 1; j <= x; j++)
		{
			cin >> y;
			v[i].push_back(y);
		}
	}
	for (int i = 1; i <= m; i++)
	{
		if (g[a[i]] == 0)
		{

			y = dfs(a[i]);
			if (g[a[i]] == 2)
			{
				b[d] = a[i];
				d++;
			}
			if (y == -1)
			{
				cout << -1;
				return 0;

			}
		}
	}
	cout << d-1 << endl;
	for (int i = 1; i < d; i++)
	{
		cout << b[i] << " ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
long long a[MAXN], b[MAXN];
long long n,y , z, t, m,f, x , d = 1, c;
vector <int> v[MAXN], h;
bool mark[MAXN],mark1[MAXN], io = false;
char g;
long long dfs (long long x)
{
//	h.push_back(s);
	mark[x] = 1;
	for (int i = 0; i < v[x].size(); i++)
	{
		if (mark[v[x][i]] == 0)
		{
			dfs(v[x][i]);
			b[d] = v[x][i];
			d++;
		}
		else
		{
			return -1;
		}
	}
	return 1;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		for (int j = 1; j <= x; j++)
		{
			cin >> y;
			v[i].push_back(y);
		}
	}
	for (int i = 1; i <= m; i++)
	{
		if (mark[a[i]] == 0)
		{
			y = dfs(a[i]);
			if (y == -1)
			{
				cout << -1;
				return 0;
			}
			b[d] = a[i];
			d++;
		}
	}
	cout << d-1 << endl;
	for (int i = 1; i < d; i++)
	{
		cout << b[i] << " ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
long long a[MAXN], b[MAXN];
long long n,y , z, t, m,f, x , d = 1, c;
vector <int> v[MAXN], h;
bool mark[MAXN],mark1[MAXN], io = false;
char g;
long long dfs (long long x)
{
//	h.push_back(s);
	mark[x] = 1;
	for (int i = 0; i < v[x].size(); i++)
	{

		if (mark[v[x][i]] == 0)
		{

			g = dfs(v[x][i]);
			if(g == -1)
				return -1;
			b[d] = v[x][i];
			d++;
		}
		else
		{
			return -1;
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		for (int j = 1; j <= x; j++)
		{
			cin >> y;
			v[i].push_back(y);
		}
	}
	for (int i = 1; i <= m; i++)
	{
		if (mark[a[i]] == 0)
		{
			y = dfs(a[i]);
//			cout << y << endl;
			if (y == -1)
			{
				cout << -1;
				return 0;
			}
			b[d] = a[i];
			d++;
		}
	}
	cout << d-1 << endl;
	for (int i = 1; i < d; i++)
	{
		cout << b[i] << " ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
vector<int> s,ans;
vector<vector<int>> vv;
set<int> t;
void dfs(int x)
{
    check[x]=true;
    t.insert(x);
    for(auto i:v[x])
    {
        if(!check[i])
        {
            dfs(i);
        }
    }
}
int main()
{
    fast
    fast
    int n,k,a,b;
    cin>>n>>k;
    vv.resize(n+1);
    v.resize(n+1);
    check.resize(n+1);
    int cnt[n+1]={};
    for(int i=0;i<k;i++)
    {
        cin>>a;
        s.pb(a);
    }
    for(int i=1;i<=n;i++)
    {
        int t;
        cin>>t;
        for(int j=0;j<t;j++)
        {
            cin>>a;
            v[i].pb(a);
            vv[a].pb(i);
            ++cnt[i];
        }
    }
    set<pair<int,int>> se;
    for(auto i:s)
    {
        dfs(i);
    }
    for(auto j:t)
    {
        se.insert({cnt[j],j});
    }
    while(!se.empty())
    {
        if((*se.begin()).F!=0)
        {
            cout<<-1;
            return 0;
        }
        ans.pb((*se.begin()).S);
        int xx=se.begin()->S;
        se.erase(se.begin());
        for(auto k:vv[xx])
        {
            if(se.count({cnt[k],k}))
                {se.erase({cnt[k],k});
                cnt[k]--;
                se.insert({cnt[k],k});}
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans)
    {
        cout<<i<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
set<int> se;
vector<vector<int>> ans;
vector<int>temp,s;
int sum=0;
queue<int>q;
void bfs(int x)
{
	q.push(x);
	check[x]=true;
	se.insert(x);
	temp.pb(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sum+=v[x].size();
		for(auto i:v[x])
		{
			if(!check[i])
			{
				q.push(i);
				check[i]=true;
				se.insert(i);
				temp.pb(i);
			}
		}
	}
}
/*void dfs(int x)
{
	check[x]=true;
	se.insert(x);
	ans.pb(x);
	sum+=v[x].size();
	for(auto i:v[x])
	{
		if(!check[i])
		{
			dfs(i);
		}
	}
}
*/int main()
{
	fast
	int n,k,a,b;
	cin>>n>>k;
	v.resize(n+1);
	check.resize(n+1);
	for(int i=0;i<k;i++)
	{
		cin>>a;
		s.pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		for(int j=0;j<t;j++)
		{
			cin>>a;
			v[i].pb(a);
		}
	}
	for(auto i:s)
	{
		if(!check[i])
		{
			bfs(i);
			if(sum!=((int)se.size()-1))
			{
				cout<<-1;
				return 0;
			}
			reverse(temp.begin(),temp.end());
			ans.pb(temp);
			temp.clear();
			se.clear();
			sum=0;
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
	{
		for(auto j:ans[i])
		{
			cout<<j<<" ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
set<int> s,se,ans;
int sum=0;
void dfs(int x)
{
	check[x]=true;
	se.insert(x);
	ans.insert(x);
	sum+=v[x].size();
	for(auto i:v[x])
	{
		if(!check[i])
		{
			dfs(i);
		}
	}
}
int main()
{
	fast
	int n,k,a,b;
	cin>>n>>k;
	v.resize(n+1);
	check.resize(n+1);
	for(int i=0;i<k;i++)
	{
		cin>>a;
		s.insert(a);
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		for(int j=0;j<t;j++)
		{
			cin>>a;
			v[i].pb(a);
		}
	}
	for(auto i:s)
	{
		if(!check[i])
		{
			dfs(i);
			if(sum!=((int)se.size()-1))
			{
				cout<<-1;
				return 0;
			}
			se.clear();
			sum=0;
		}
	}
	cout<<ans.size()<<endl;
	for(auto i:ans)
	{
		cout<<i<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
set<int> s,se;
vector<vector<int>> ans;
vector<int>temp;
int sum=0;
queue<int>q;
void bfs(int x)
{
	q.push(x);
	check[x]=true;
	se.insert(x);
	temp.pb(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sum+=v[x].size();
		for(auto i:v[x])
		{
			if(!check[i])
			{
				q.push(i);
				check[i]=true;
				se.insert(i);
				temp.pb(i);
			}
		}
	}
}
/*void dfs(int x)
{
	check[x]=true;
	se.insert(x);
	ans.pb(x);
	sum+=v[x].size();
	for(auto i:v[x])
	{
		if(!check[i])
		{
			dfs(i);
		}
	}
}
*/int main()
{
	fast
	int n,k,a,b;
	cin>>n>>k;
	v.resize(n+1);
	check.resize(n+1);
	for(int i=0;i<k;i++)
	{
		cin>>a;
		s.insert(a);
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		for(int j=0;j<t;j++)
		{
			cin>>a;
			v[i].pb(a);
		}
	}
	for(auto i:s)
	{
		if(!check[i])
		{
			bfs(i);
			if(sum!=((int)se.size()-1))
			{
				cout<<-1;
				return 0;
			}
			reverse(temp.begin(),temp.end());
			ans.pb(temp);
			temp.clear();
			se.clear();
			sum=0;
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
	{
		for(auto j:ans[i])
		{
			cout<<j<<" ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
vector<int> s,ans;
vector<vector<int>> vv;
set<int> t;
void dfs(int x)
{
	check[x]=true;
	t.insert(x);
	for(auto i:v[x])
	{
		if(!check[i])
		{
			dfs(i);
		}
	}
}
int main()
{
	fast
	fast
	int n,k,a,b;
	cin>>n>>k;
	vv.resize(n+1);
	v.resize(n+1);
	check.resize(n+1);
	int cnt[n+1]={};
	for(int i=0;i<k;i++)
	{
		cin>>a;
		s.pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		for(int j=0;j<t;j++)
		{
			cin>>a;
			v[i].pb(a);
			vv[a].pb(i);
			++cnt[i];
		}
	}
	set<pair<int,int>> se;
	for(auto i:s)
	{
		dfs(i);
	}
	for(auto j:t)
	{
		se.insert({cnt[j],j});
	}
	while(!se.empty())
	{
		if((*se.begin()).F!=0)
		{
			cout<<-1;
			return 0;
		}
		ans.pb((*se.begin()).S);
		for(auto k:vv[(*se.begin()).S])
		{
			if(se.count({cnt[k],k}))
				{se.erase({cnt[k],k});
				cnt[k]--;
				se.insert({cnt[k],k});}
		}
		se.erase(se.begin());
	}
	cout<<ans.size()<<endl;
	for(auto i:ans)
	{
		cout<<i<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
vector<vector<int>> v;
vector<bool> check;
set<int> se;
vector<vector<int>> ans;
vector<int>temp,s;
int sum=0;
queue<int>q;
void bfs(int x)
{
	q.push(x);
	check[x]=true;
	se.insert(x);
	temp.pb(x);
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		sum+=v[x].size();
		for(auto i:v[x])
		{
			if(!check[i])
			{
				q.push(i);
				check[i]=true;
				se.insert(i);
				temp.pb(i);
			}
		}
	}
}
/*void dfs(int x)
{
	check[x]=true;
	se.insert(x);
	ans.pb(x);
	sum+=v[x].size();
	for(auto i:v[x])
	{
		if(!check[i])
		{
			dfs(i);
		}
	}
}
*/int main()
{
	fast
	int n,k,a,b;
	cin>>n>>k;
	v.resize(n+1);
	check.resize(n+1);
	for(int i=0;i<k;i++)
	{
		cin>>a;
		s.pb(a);
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		for(int j=0;j<t;j++)
		{
			cin>>a;
			v[i].pb(a);
		}
	}
	for(auto i:s)
	{
		if(!check[i])
		{
			bfs(i);
			if(sum!=((int)se.size()-1))
			{
				cout<<-1;
				return 0;
			}
			reverse(temp.begin(),temp.end());
			ans.pb(temp);
			temp.clear();
			se.clear();
			sum=0;
		}
	}
	int ans1=0;
	for(int i=0;i<ans.size();i++)
	{
		ans1+=(int)(ans[i].size());
	}
	cout<<ans1<<endl;
	for(int i=0;i<ans.size();i++)
	{
		for(auto j:ans[i])
		{
			cout<<j<<" ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define ppi pair<int,int>
#define pppi pair<ppi,int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define endl '\n'
#define reflex ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define int long long
#define INF ((ll)1e18 + 1)
using namespace std;
const int N = 100005;
int M[N], in[N], done[N], vis[N], imp[N];
vi adj[N],bdj[N];
stack<int> s;
vi q;
void dfs2(int x){
    int ok = M[x];
    for(int y:adj[x]){
        if(imp[y]==1){
            dfs2(y);
            ok = ok|imp[y];
        }
    }
    imp[x] = ok;
}
void dfs(int source,int transpose)
{
    if(transpose==0)
    {
        for(int i=0;i<adj[source].size();i++)
        {
            if(!vis[adj[source][i]])
            {
                vis[adj[source][i]]=1;
                dfs(adj[source][i],transpose);
            }
        }
        s.push(source);
    }
    else
    {
        q.pb(source);
        for(int i=0;i<bdj[source].size();i++)
        {
            if(!vis[bdj[source][i]])
            {
                vis[bdj[source][i]]=1;
                dfs(bdj[source][i],transpose);
            }
        }
    }
}
void solve(){
    int k,n,x;
    cin>>n>>k;
    rep(i,1,k){
        cin>>x;
        M[x] = 1;
    }
    rep(i,1,n){
        int s;
        imp[i] = 1;
        cin>>s;
        rep(j,1,s){
            cin>>x;
            adj[x].pb(i);
            bdj[i].pb(x);
            in[i]++;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i,0);
        }
    }
    memset(vis,0,sizeof(vis));
    int  ans=0;
    while(!s.empty()){
        int source=s.top();
        s.pop();
        if(vis[source]==0){
            q.clear();
            vis[source]=1;
            dfs(source,1);
            if(q.size()>1){
                for(int x : q)
                    imp[x] = 0;
            }
        }
    }
    queue<int> dq;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(imp[i]==1 and vis[i]==0){
            vis[i] = 1;
            dfs2(i);
            if(imp[i]==1){
                if(in[i]==0){
                    dq.push(i);
                    done[i] = 1;
                }
            }
        }
    }
    int cnt = 0;
    vi v;
    while(!dq.empty()){
        x = dq.front();
        dq.pop();
        v.pb(x);
        if(M[x]==1)
            cnt++;
        for(int i:adj[x]){
            if(done[i]==0 and imp[i]){
                in[i]--;
                if(in[i]==0){
                    done[i] = 1;
                    dq.push(i);
                }
            }
        }
    }
    if(cnt!=k)
        cout<<-1<<endl;
    else{
        cout<<v.size()<<endl;
        for(int x:v)
            cout<<x<<" ";
    }
}
signed main(){
    int t;
    reflex;
    t = 1;
    while(t--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define ppi pair<int,int>
#define pppi pair<ppi,int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define endl '\n'
#define reflex ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define INF ((ll)1e18 + 1)
#define fastscan(x) scanf("%d",&x)
using namespace std;
const int N = 100005;
int M[N], in[N], done[N], vis[N], imp[N];
vi adj[N],bdj[N];
stack<int> s;
int tk = 0;
void dfs2(int x){
    int ok = M[x];
    for(int y:adj[x]){
        if(imp[y]==1){
            vis[y] = 1;
            dfs2(y);
            ok = ok|imp[y];
        }
    }
    imp[x] = ok;
}
void dfs(int source,int transpose)
{
    if(transpose==0)
    {
        for(int i=0;i<adj[source].size();i++)
        {
            if(!vis[adj[source][i]])
            {
                vis[adj[source][i]]=1;
                dfs(adj[source][i],transpose);
            }
        }
        s.push(source);
    }
    else
    {
        imp[source] = 0;
        tk++;
        for(int i=0;i<bdj[source].size();i++)
        {
            if(!vis[bdj[source][i]])
            {
                vis[bdj[source][i]]=1;
                dfs(bdj[source][i],transpose);
            }
        }
    }
}
void solve(){
    int k,n,x;
    fastscan(n);
    fastscan(k);
    rep(i,1,k){
        fastscan(x);
        M[x] = 1;
    }
    rep(i,1,n){
        int s;
        imp[i] = 1;
        fastscan(s);
        rep(j,1,s){
            fastscan(x);
            adj[x].pb(i);
            bdj[i].pb(x);
            in[i]++;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i,0);
        }
    }
    memset(vis,0,sizeof(vis));
    int  ans=0;
    while(!s.empty()){
        int source=s.top();
        s.pop();
        if(vis[source]==0){
            tk = 0;
            vis[source]=1;
            dfs(source,1);
            if(tk==1)
                imp[source] = 1;
        }
    }
    queue<int> dq;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(imp[i]==1 and vis[i]==0){
            vis[i] = 1;
            dfs2(i);
        }
        if(imp[i]==1){
            if(in[i]==0){
                dq.push(i);
                done[i] = 1;
            }
        }
    }
    int cnt = 0;
    vi v;
    while(!dq.empty()){
        x = dq.front();
        dq.pop();
        v.pb(x);
        if(M[x]==1)
            cnt++;
        for(int i:adj[x]){
            if(done[i]==0 and imp[i]){
                in[i]--;
                if(in[i]==0){
                    done[i] = 1;
                    dq.push(i);
                }
            }
        }
    }
    if(cnt!=k)
        printf("-1");
    else{
        printf("%d\n", sz(v));
        for(int x:v)
            printf("%d ",x);
    }
}
signed main(){
    int t;
    t = 1;
    while(t--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define ppi pair<int,int>
#define pppi pair<ppi,int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define endl '\n'
#define reflex ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define INF ((ll)1e18 + 1)
using namespace std;
const int N = 100005;
int M[N], in[N], done[N], vis[N], imp[N];
vi adj[N],bdj[N];
stack<int> s;
vi q;
void dfs2(int x){
    int ok = M[x];
    for(int y:adj[x]){
        if(imp[y]==1){
            dfs2(y);
            ok = ok|imp[y];
        }
    }
    imp[x] = ok;
}
void dfs(int source,int transpose)
{
    if(transpose==0)
    {
        for(int i=0;i<adj[source].size();i++)
        {
            if(!vis[adj[source][i]])
            {
                vis[adj[source][i]]=1;
                dfs(adj[source][i],transpose);
            }
        }
        s.push(source);
    }
    else
    {
        q.pb(source);
        for(int i=0;i<bdj[source].size();i++)
        {
            if(!vis[bdj[source][i]])
            {
                vis[bdj[source][i]]=1;
                dfs(bdj[source][i],transpose);
            }
        }
    }
}
inline void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
void solve(){
    int k,n,x;
    fastscan(n);
    fastscan(k);
    rep(i,1,k){
        fastscan(x);
        M[x] = 1;
    }
    rep(i,1,n){
        int s;
        imp[i] = 1;
        fastscan(s);
        rep(j,1,s){
            fastscan(x);
            adj[x].pb(i);
            bdj[i].pb(x);
            in[i]++;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i,0);
        }
    }
    memset(vis,0,sizeof(vis));
    int  ans=0;
    while(!s.empty()){
        int source=s.top();
        s.pop();
        if(vis[source]==0){
            q.clear();
            vis[source]=1;
            dfs(source,1);
            if(q.size()>1){
                for(int x : q)
                    imp[x] = 0;
            }
        }
    }
    queue<int> dq;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(imp[i]==1 and vis[i]==0){
            vis[i] = 1;
            dfs2(i);
            if(imp[i]==1){
                if(in[i]==0){
                    dq.push(i);
                    done[i] = 1;
                }
            }
        }
    }
    int cnt = 0;
    vi v;
    while(!dq.empty()){
        x = dq.front();
        dq.pop();
        v.pb(x);
        if(M[x]==1)
            cnt++;
        for(int i:adj[x]){
            if(done[i]==0 and imp[i]){
                in[i]--;
                if(in[i]==0){
                    done[i] = 1;
                    dq.push(i);
                }
            }
        }
    }
    if(cnt!=k)
        printf("-1");
    else{
        cout<<v.size()<<endl;
        for(int x:v)
            printf("%d ",x);
    }
}
signed main(){
    int t;
    t = 1;
    while(t--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define ppi pair<int,int>
#define pppi pair<ppi,int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define endl '\n'
#define reflex ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define INF ((ll)1e18 + 1)
#define fastscan(x) scanf("%d",&x)
using namespace std;
const int N = 100005;
int M[N], in[N], done[N], vis[N], imp[N];
vi adj[N],bdj[N];
stack<int> s;
vi q;
void dfs2(int x){
    int ok = M[x];
    for(int y:adj[x]){
        if(imp[y]==1){
            dfs2(y);
            ok = ok|imp[y];
        }
    }
    imp[x] = ok;
}
void dfs(int source,int transpose)
{
    if(transpose==0)
    {
        for(int i=0;i<adj[source].size();i++)
        {
            if(!vis[adj[source][i]])
            {
                vis[adj[source][i]]=1;
                dfs(adj[source][i],transpose);
            }
        }
        s.push(source);
    }
    else
    {
        q.pb(source);
        for(int i=0;i<bdj[source].size();i++)
        {
            if(!vis[bdj[source][i]])
            {
                vis[bdj[source][i]]=1;
                dfs(bdj[source][i],transpose);
            }
        }
    }
}
void solve(){
    int k,n,x;
    fastscan(n);
    fastscan(k);
    rep(i,1,k){
        fastscan(x);
        M[x] = 1;
    }
    rep(i,1,n){
        int s;
        imp[i] = 1;
        fastscan(s);
        rep(j,1,s){
            fastscan(x);
            adj[x].pb(i);
            bdj[i].pb(x);
            in[i]++;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i,0);
        }
    }
    memset(vis,0,sizeof(vis));
    int  ans=0;
    while(!s.empty()){
        int source=s.top();
        s.pop();
        if(vis[source]==0){
            q.clear();
            vis[source]=1;
            dfs(source,1);
            if(q.size()>1){
                for(int x : q)
                    imp[x] = 0;
            }
        }
    }
    queue<int> dq;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(imp[i]==1 and vis[i]==0){
            vis[i] = 1;
            dfs2(i);
            if(imp[i]==1){
                if(in[i]==0){
                    dq.push(i);
                    done[i] = 1;
                }
            }
        }
    }
    int cnt = 0;
    vi v;
    while(!dq.empty()){
        x = dq.front();
        dq.pop();
        v.pb(x);
        if(M[x]==1)
            cnt++;
        for(int i:adj[x]){
            if(done[i]==0 and imp[i]){
                in[i]--;
                if(in[i]==0){
                    done[i] = 1;
                    dq.push(i);
                }
            }
        }
    }
    if(cnt!=k)
        printf("-1");
    else{
        cout<<v.size()<<endl;
        for(int x:v)
            printf("%d ",x);
    }
}
signed main(){
    int t;
    t = 1;
    while(t--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define ppi pair<int,int>
#define pppi pair<ppi,int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define endl '\n'
#define reflex ios_base::sync_with_stdio(false)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define INF ((ll)1e18 + 1)
#define fastscan(x) scanf("%d",&x)
using namespace std;
const int N = 100005;
int M[N], in[N], done[N], vis[N], imp[N];
vi adj[N],bdj[N];
stack<int> s;
int tk = 0;
void dfs2(int x){
    int ok = M[x];
    for(int y:adj[x]){
        if(imp[y]==1){
            if(vis[y]==0){
                vis[y] = 1;
                dfs2(y);
            }
            ok = ok|imp[y];
        }
    }
    imp[x] = ok;
}
void dfs(int source,int transpose)
{
    if(transpose==0)
    {
        for(int i=0;i<adj[source].size();i++)
        {
            if(!vis[adj[source][i]])
            {
                vis[adj[source][i]]=1;
                dfs(adj[source][i],transpose);
            }
        }
        s.push(source);
    }
    else
    {
        imp[source] = 0;
        tk++;
        for(int i=0;i<bdj[source].size();i++)
        {
            if(!vis[bdj[source][i]])
            {
                vis[bdj[source][i]]=1;
                dfs(bdj[source][i],transpose);
            }
        }
    }
}
void solve(){
    int k,n,x;
    fastscan(n);
    fastscan(k);
    rep(i,1,k){
        fastscan(x);
        M[x] = 1;
    }
    rep(i,1,n){
        int s;
        imp[i] = 1;
        fastscan(s);
        rep(j,1,s){
            fastscan(x);
            adj[x].pb(i);
            bdj[i].pb(x);
            in[i]++;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            vis[i]=1;
            dfs(i,0);
        }
    }
    memset(vis,0,sizeof(vis));
    int  ans=0;
    while(!s.empty()){
        int source=s.top();
        s.pop();
        if(vis[source]==0){
            tk = 0;
            vis[source]=1;
            dfs(source,1);
            if(tk==1)
                imp[source] = 1;
        }
    }
    queue<int> dq;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        if(imp[i]==1 and vis[i]==0){
            vis[i] = 1;
            dfs2(i);
        }
        if(imp[i]==1){
            if(in[i]==0){
                dq.push(i);
                done[i] = 1;
            }
        }
    }
    int cnt = 0;
    vi v;
    while(!dq.empty()){
        x = dq.front();
        dq.pop();
        v.pb(x);
        if(M[x]==1)
            cnt++;
        for(int i:adj[x]){
            if(done[i]==0 and imp[i]){
                in[i]--;
                if(in[i]==0){
                    done[i] = 1;
                    dq.push(i);
                }
            }
        }
    }
    if(cnt!=k)
        printf("-1");
    else{
        printf("%d\n", sz(v));
        for(int x:v)
            printf("%d ",x);
    }
}
signed main(){
    int t;
    t = 1;
    while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <ll> V[100005];
vector <ll> R;
ll M[100005];
ll G[100005];
void dfs(ll x){
    if(M[x]==2)return ;
    G[x]=1;
    //cout<<"x="<<x<<"\n";
    for(ll i=0;i<V[x].size();i++){
        //cout<<"   new x="<<V[x][i]<<"\n";
		if(M[V[x][i]]==1){
            cout<<-1;
            exit(0);
        }
		dfs(V[x][i]);
    }
    R.push_back(x);
    G[x]=2;
}
int main()
{
    //ifstream cin("in.in");
    ll n,k;
    cin>>n>>k;
    for(ll i=0;i<k;i++){
        cin>>M[i];
    }
    for(ll i=1;i<=n;i++){
        ll m,a;
        cin>>m;
        for(ll j=0;j<m;j++){
            cin>>a;
            V[i].push_back(a);
            //cout<<i<<" "<<a<<"\n";
        }
    }
    for(ll i=0;i<k;i++){
        dfs(M[i]);
        //cout<<M[i]<<"M\n";
    }
    cout<<R.size()<<"\n";
    for(ll i=0;i<R.size();i++){
        cout<<R[i]<<" ";
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <ll> V[100005];
vector <ll> R;
ll M[100005];
ll G[100005];
void dfs(ll x){
    if(G[x]==2)return;
    if(G[x]==1){cout<<-1; exit(0);}
    G[x]=1;
    //cout<<"x="<<x<<"\n";
    for(ll i=0;i<V[x].size();i++){
        //cout<<"   new x="<<V[x][i]<<"\n";
		dfs(V[x][i]);
    }
    R.push_back(x);
    G[x]=2;
}
int main()
{
    ifstream cin("in.in");
    ll n,k;
    cin>>n>>k;
    for(ll i=0;i<k;i++){
        cin>>M[i];
    }
    for(ll i=1;i<=n;i++){
        ll m,a;
        cin>>m;
        for(ll j=0;j<m;j++){
            cin>>a;
            V[i].push_back(a);
            //cout<<i<<" "<<a<<"\n";
        }
    }
    for(ll i=0;i<k;i++){
        dfs(M[i]);
        //cout<<M[i]<<"M\n";
    }
    cout<<R.size()<<"\n";
    for(ll i=0;i<R.size();i++){
        cout<<R[i]<<" ";
    }
}


blob

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <ll> V[100005];
vector <ll> R;
ll M[100005];
ll G[100005];
void dfs(ll x){
    if(M[x]==2)return ;
    M[x]=1;
    for(ll i=0;i<V[x].size();i++){
		if(M[V[x][i]]==1){
            cout<<-1;
            return;
        }
		dfs(M[V[x][i]]);
    }
    R.push_back(x);
    M[x]=2;
}
int main()
{
    ifstream cin("in.in");
    ll n,k;
    cin>>n>>k;
    for(ll i=0;i<k;i++){
        cin>>M[i];
    }
    for(ll i=1;i<=n;i++){
        ll m,a;
        cin>>m>>a;
        for(ll j=0;j<m;j++){
            cin>>a;
            V[a].push_back(i);
            G[i]++;
        }
    }
    for(ll i=1;i<=n;i++){
        if(G[i]==0);
        dfs(i);
    }
    cout<<R.size()<<"\n";
    for(ll i=0;i<R.size();i++){
        cout<<R[i]<<" ";
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <ll> V[100005];
vector <ll> R;
ll M[100005];
ll G[100005];
void dfs(ll x){
    if(G[x]==2)return;
    if(G[x]==1){cout<<-1; exit(0);}
    G[x]=1;
    //cout<<"x="<<x<<"\n";
    for(ll i=0;i<V[x].size();i++){
        //cout<<"   new x="<<V[x][i]<<"\n";
		dfs(V[x][i]);
    }
    R.push_back(x);
    G[x]=2;
}
int main()
{
    //ifstream cin("in.in");
    ll n,k;
    cin>>n>>k;
    for(ll i=0;i<k;i++){
        cin>>M[i];
    }
    for(ll i=1;i<=n;i++){
        ll m,a;
        cin>>m;
        for(ll j=0;j<m;j++){
            cin>>a;
            V[i].push_back(a);
            //cout<<i<<" "<<a<<"\n";
        }
    }
    for(ll i=0;i<k;i++){
        dfs(M[i]);
        //cout<<M[i]<<"M\n";
    }
    cout<<R.size()<<"\n";
    for(ll i=0;i<R.size();i++){
        cout<<R[i]<<" ";
    }
}


/*input
3 3
1 2 3
1 2
1 3
1 1
*/
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ps putchar(' ')
#define pn putchar('\n')
#define ppb pop_back
#define mp make_pair
#define ft first
#define sd second
#define sz size()
#define bn begin()
#define ed end()
#define get(x) scanf("%d", &x);
#define getl(x) scanf("%I64d", &x);
#define PI acos(0)*2

using namespace std;

inline void pi(int x){if(x==0){putchar('0');return;}char c[10];int k=0;if(x<0){putchar('-');x=-x;}while(x){int nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void pl(ll x){if(x==0){putchar('0');return;}char c[19];int k=0;if(x<0){putchar('-');x=-x;}while(x){ll nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void gi(int &val){char c;do{c=getchar();}while(c<'0'||c>'9');if(c=='-'){val=-1;}else{val=c-'0';}c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}}
inline void gl(ll &val){char c;do{c=getchar();}while(c<'0'||c>'9');if(c=='-'){val=-1;}else{val=c-'0';}c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}}
inline void gl(ll &val1,ll &val2){gl(val1);gl(val2);}
inline void gi(int &val1,int &val2){gi(val1);gi(val2);}
inline void gl(ll &val1,ll &val2,ll &val3){gl(val1);gl(val2);gl(val3);}
inline void gi(int &val1,int &val2,int &val3){gi(val1);gi(val2);gi(val3);}

const int N = 1e5 + 7, M = 150000, mod = 1000000007, inf = 1000000007;
const ll lmod = 1000000007, linf = 1e18 + 77;
const ld eps = 1e-14;

int n, k;

int a[N];

vector <int> g[N];

int ans[N];

int cur[N];

bool isdone[N];

vector <int> done;

int go(int v) {
  cur[v] = 1;
  if (ans[v] != -1) {
    return ans[v];
  }
  int sum = 0;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (cur[to]) {
      cout << -1 << endl;
      exit(0);
    }
    sum += go(to);
  }
  cur[v] = 0;
  if (!isdone[v]) {
    isdone[v] = 1;
    done.pb(v);
  }
  ans[v] = sum;
  return sum;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, k;
  gi(n, k);
  for (int i = 0; i < k; i++) {
    gi(a[i]);
    a[i]--;
  }

  for (int i = 0; i < n; i++) {
    ans[i] = -1;
    int t;
    gi(t);

    for (int j = 0; j < t; j++) {
      int u;
      gi(u);
      u--;
      g[i].pb(u);
    }
  }

  for (int i = 0; i < k; i++) {
    go(a[i]);
  }

  cout << done.size() << endl;

  for (int i = 0; i < done.size(); i++) {
    cout << done[i] + 1 << " ";
  }

}


/*input
3 3
1 2 3
1 2
1 3
1 1
*/
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ps putchar(' ')
#define pn putchar('\n')
#define ppb pop_back
#define mp make_pair
#define ft first
#define sd second
#define sz size()
#define bn begin()
#define ed end()
#define get(x) scanf("%d", &x);
#define getl(x) scanf("%I64d", &x);
#define PI acos(0)*2

using namespace std;

inline void pi(int x){if(x==0){putchar('0');return;}char c[10];int k=0;if(x<0){putchar('-');x=-x;}while(x){int nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void pl(ll x){if(x==0){putchar('0');return;}char c[19];int k=0;if(x<0){putchar('-');x=-x;}while(x){ll nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void gi(int &val){char c;do{c=getchar();}while(c<'0'||c>'9');if(c=='-'){val=-1;}else{val=c-'0';}c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}}
inline void gl(ll &val){char c;do{c=getchar();}while(c<'0'||c>'9');if(c=='-'){val=-1;}else{val=c-'0';}c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}}
inline void gl(ll &val1,ll &val2){gl(val1);gl(val2);}
inline void gi(int &val1,int &val2){gi(val1);gi(val2);}
inline void gl(ll &val1,ll &val2,ll &val3){gl(val1);gl(val2);gl(val3);}
inline void gi(int &val1,int &val2,int &val3){gi(val1);gi(val2);gi(val3);}

const int N = 1e5 + 7, M = 150000, mod = 1000000007, inf = 1000000007;
const ll lmod = 1000000007, linf = 1e18 + 77;
const ld eps = 1e-14;

int n, k;

int a[N];

vector <int> g[N];

bool used[N];

int cur[N];

bool isdone[N];

vector <int> done;

void go(int v) {
  cur[v] = 1;
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (cur[to]) {
      cout << -1 << endl;
      exit(0);
    }
    if (!used[to]) {
      go(to);
    }
  }
  cur[v] = 0;
  if (!isdone[v]) {
    isdone[v] = 1;
    done.pb(v);
  }
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, k;
  gi(n, k);
  for (int i = 0; i < k; i++) {
    gi(a[i]);
    a[i]--;
  }

  for (int i = 0; i < n; i++) {

    int t;

    gi(t);

    for (int j = 0; j < t; j++) {

      int u;
      gi(u);
      u--;
      g[i].pb(u);

    }

  }

  for (int i = 0; i < k; i++) {
    if (!used[a[i]]) {
      go(a[i]);
    }
  }

  cout << done.size() << endl;

  for (int i = 0; i < done.size(); i++) {
    cout << done[i] + 1 << " ";
  }

}


/*input
3 3
1 2 3
1 2
1 3
1 1
*/
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ps putchar(' ')
#define pn putchar('\n')
#define ppb pop_back
#define mp make_pair
#define ft first
#define sd second
#define sz size()
#define bn begin()
#define ed end()
#define get(x) scanf("%d", &x);
#define getl(x) scanf("%I64d", &x);
#define PI acos(0)*2
#define puts myputs
#define gets mygets

using namespace std;

inline void pi(int x){if(x==0){putchar('0');return;}char c[10];int k=0;if(x<0){putchar('-');x=-x;}while(x){int nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void pin(const int&x){pi(x);putchar('\n');};
inline void pl(ll x){if(x==0){putchar('0');return;}char c[19];int k=0;if(x<0){putchar('-');x=-x;}while(x){ll nx=x/10;c[k++]=x-nx*10;x=nx;}while(k--){putchar(c[k]+'0');}}
inline void pln(const ll&x){pl(x);putchar('\n');};
inline void gi(int&val){val=1;char c;do{c=getchar();}while(c!='-'&&(c<'0'||c>'9'));int zn=1;if(c=='-'){zn=-1;c=getchar();}val=c-'0';c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}val*=zn;}
//inline void gl(ll&val){char c;do{c=getchar();}while(c<'0'||c>'9');if(c=='-'){val=-1;}else{val=c-'0';}c=getchar();while(c>='0'&&c<='9'){val*=10;val+=c-'0';c=getchar();}}
//inline void gl(ll&val1,ll&val2){gl(val1);gl(val2);}
inline void gi(int&val1,int&val2){gi(val1);gi(val2);}
//inline void gl(ll&val1,ll&val2,ll&val3){gl(val1);gl(val2);gl(val3);}
inline void gi(int&val1,int&val2,int&val3){gi(val1);gi(val2);gi(val3);}
inline void mygets(char*b){int i=0;for(;;++i){const char c=getchar();if(c=='\n'||c==EOF){break;}b[i]=c;}b[i]='\0';}
inline void mygets(string&b){int i=0;for(;;++i){const char c=getchar();if(c=='\n'||c==EOF){break;}b.pb(c);}}
inline void mygets(char&b){b=getchar();getchar();}
inline void myputs(const string&b){for(int i=0;i<b.size();++i){putchar(b[i]);}}
inline void putsn(const string&b){puts(b);putchar('\n');}
inline void myputs(const char&b){putchar(b);}
inline void putsn(const char&b){putchar(b);putchar('\n');}

const int N = 1e5 + 7, M = 150000, mod = 1000000007, inf = 1000000007;
const ll lmod = 1000000007, linf = 1e18 + 77;
const ld eps = 1e-14;

int n, k;

int a[N];

vector <int> g[N];

bool used[N];

int cur[N];

bool isdone[N];

vector <int> done;

void go(int v) {
  cur[v] = 1;
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (cur[to]) {
      cout << -1 << endl;
      exit(0);
    }
    if (!used[to]) {
      go(to);
    }
  }
  cur[v] = 0;
  if (!isdone[v]) {
    isdone[v] = 1;
    done.pb(v);
  }
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, k;
  gi(n, k);
  for (int i = 0; i < k; i++) {
    gi(a[i]);
    a[i]--;
  }

  for (int i = 0; i < n; i++) {

    int t;

    gi(t);

    for (int j = 0; j < t; j++) {

      int u;
      gi(u);
      u--;
      g[i].pb(u);

    }

  }

  for (int i = 0; i < k; i++) {
    if (!used[a[i]]) {
      go(a[i]);
    }
  }

  pin(done.size());

  for (int i = 0; i < done.size(); i++) {
    pi(done[i] + 1);
    ps;
  }

}


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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <ll, ll> pll;

template<class T> using V = vector<T>;

typedef V <int> vi;
typedef V <ll> vll;
typedef V <pi> vpi;
typedef V <pll> vpll;

const int INF = int(1e9) + 7;
const ll LINF = ll(1e18) + 9;

struct _ {
	_()	{
		ios_base::Init i;
		cin.sync_with_stdio(0);
		cin.tie(NULL);
		cout << fixed << setprecision(25);
		srand(time(NULL));
#define deb(x) cerr << #x << " = " << x << '\n'
#define all(ContainerName) ContainerName.begin(),ContainerName.end()
#ifndef DEBUG
#define cerr if(0)cerr
#endif
#ifdef DEBUG
			freopen("input.txt", "r", stdin);
//			freopen("output.txt", "w", stdout);
#endif
	}
} _;

V <vi> g;
vi used;
vi ans;

void dfs (int v) {

	switch (used[v]) {
		case 1: return; break;
		case -1: cout << -1, exit(0);
	}

	used[v] = -1;

	for (auto i : g[v])
		dfs(i);

	used[v] = 1;
	ans.push_back(v + 1);
}

void solve () {

	int n, k;
	cin >> n >> k;

	g = V <vi> (n);

	vi need = vi (k);
	for (auto& i : need)
		cin >> i, --i;

	for (auto& i : g) {
		int t;
		cin >> t;
		i = vi (t);
		for (auto& re : i)
			cin >> re, --re;
	}

	used = vi (n);
	for (auto i : need)
		dfs(i);

	cout << ans.size() << '\n';
	for (auto i : ans)
		cout << i << ' ';
}

int main() {

	solve();

	cerr << "\n\n\nTIME  =  " << int(clock()*ld(1000)/CLOCKS_PER_SEC) << '\n';
	return 0;
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    //cout << "Cur ver:" << st << endl;
    used[st] = 1;
    for(auto it:gr[st]){
        if(used[it] == 1){
            //cout << "FALSE HERE:" << " FROM:" << st << " TO:"<<it<<endl;
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
    }
    used[st] = 2;
    ans.push_back(st);
    //cout << "LEAVED FROM:"<<st <<endl;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    //reverse(ans.begin(),ans.end());
    if(!flag){
        cout << -1;
        return 0;
    }
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    //cout << "Cur ver:" << st << endl;
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            //cout << "FALSE HERE:" << " FROM:" << st << " TO:"<<it<<endl;
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
    }
    used[st] = 2;
    //cout << "LEAVED FROM:"<<st <<endl;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include <bits/stdc++.h>

using namespace std;

void dfs(auto &gr,auto &used,auto &ans,int st,bool flag){
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            flag == false;
        }
        else if(used[it] != 2){
            dfs(gr,used,ans,it,flag);
        }
    }
    used[st] = 2;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int>>gr(n+1);
    vector<int>used(n+1);
    vector<int>vaz(k);
    vector<int>ans;
    bool flag = true;
    for(int i = 0;i<k;i++){
        cin >> vaz[i];
    }
    for(int i = 1;i<=n+1;i++){
        int temp;
        cin >> temp;
        for(int j = 0;j<temp;j++){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    for(int it:vaz){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(used[it] == 0){
            dfs(gr,used,ans,it,flag);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int it:ans){
        cout << it << ' ';
    }
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
        used[st] = 2;
    }
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
        used[st] = 2;
    }
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
    }
    used[st] = 2;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include<bits/stdc++.h>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);

long long MOD = 1000000007;
using namespace std;

void dfs1(auto &gr,auto &used,int st,auto &ans,bool &flag){
    //cout << "Cur ver:" << st << endl;
    used[st] = 1;
    for(auto it:gr[st]){
        if(used[it] == 1){
            //cout << "FALSE HERE:" << " FROM:" << st << " TO:"<<it<<endl;
            flag = false;
        }
        else{
            if(used[it] != 2){
                dfs1(gr,used,it,ans,flag);
            }
        }
    }
    used[st] = 2;
    ans.push_back(st);
    //cout << "LEAVED FROM:"<<st <<endl;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>mn(k);
    rep(i,0,k){
        cin >> mn[i];
    }
    vector<vector<int>>gr(n+1);
    rep(i,1,n+1){
        int ver_num;cin >> ver_num;
        rep(j,0,ver_num){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    vector<int>used(n+1);
    vector<int>ans;
    bool flag = true;
    for(int cur_v:mn){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(!used[cur_v]){
            dfs1(gr,used,cur_v,ans,flag);
        }
    }
    //reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int kal:ans){
        cout << kal << ' ';
    }
}


#include <bits/stdc++.h>

using namespace std;

void dfs(auto &gr,auto &used,auto &ans,int st,bool flag){
    used[st] = 1;
    ans.push_back(st);
    for(auto it:gr[st]){
        if(used[it] == 1){
            flag == false;
        }
        else if(used[it] != 2){
            dfs(gr,used,ans,it,flag);
        }
    }
    used[st] = 2;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int>>gr(n+1);
    vector<int>used(n+1);
    vector<int>vaz(k);
    vector<int>ans;
    bool flag = true;
    for(int i = 0;i<k;i++){
        cin >> vaz[i];
    }
    for(int i = 1;i<=n;i++){
        int temp;
        cin >> temp;
        for(int j = 0;j<temp;j++){
            int tt;cin >> tt;
            gr[i].push_back(tt);
        }
    }
    //cout << "HUI" <<endl;
    for(int it:vaz){
        if(!flag){
            cout << -1;
            return 0;
        }
        if(used[it] == 0){
            dfs(gr,used,ans,it,flag);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << endl;
    for(int it:ans){
        cout << it << ' ';
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];
ll  has[1000000];
queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    if(has[i]==1)
        pp=1;

    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            return 1;
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        has[x]=1;
        v.push_back(x);
    }
    ll lp=1;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
        if(m>0)
            lp=0;
    }
    if(lp)
    {
        cout<<v.size()<<"\n";
        for(i=0;i<v.size();i++)
            cout<<v[i]<<" ";
    }
    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            pp=0;
            if(detect_(i)&&pp==1)
                p=1;
        }
    }

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

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];
ll  has[1000000];
queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    if(has[i]==1)
        pp=1;
    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            return 1;
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        has[x]=1;
        v.push_back(x);
    }

    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
    }

    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            pp=0;
            if(detect_(i)&&pp==1)
                p=1;
        }
    }

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

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];

queue<int> st;
ll pp;

bool dfs(ll i)
{
    visited[i]=1;
    ll j;
    //cout<<i<<endl;

    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&dfs(g[i][j]))
            return 1;

    }
    st.push(i);
    visited[i]=2;
    return 0;
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }

    }

    int p=1;
    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            if(dfs(v[i]))
                {
                    cout<<-1;
                    return 0;
                }
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];

queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;

    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            {
                visited[i]=4;
                return 1;
            }
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            {
                visited[i]=4;
                return 1;
            }
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    ll lp=1;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
        if(m>0)
            lp=0;
    }
    if(lp)
    {
        cout<<v.size()<<"\n";
        for(i=0;i<v.size();i++)
            cout<<v[i]<<" ";
        return 0;
    }
    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            detect_(i);
        }
    }

    for(i=0;i<v.size();i++)
    {
        if(visited[v[i]]==4)
            p=1;
    }
    if(p)
    {
        cout<<-1;
        return 0;
    }

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];

queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    ll pq=0;
    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            {
                visited[i]=4;
                pp=1;
            }
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            {
                visited[i]=4;
                pp=1;
            }
    }
    if(pp)
        return 1;
    if(visited[i]==1)
        visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    ll lp=1;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
        if(m>0)
            lp=0;
    }
    if(lp)
    {
        cout<<v.size()<<"\n";
        for(i=0;i<v.size();i++)
            cout<<v[i]<<" ";
        return 0;
    }
    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            detect_(i);
        }
    }

    for(i=0;i<v.size();i++)
    {
        if(visited[v[i]]==4)
            p=1;
    }
    if(p)
    {
        cout<<-1;
        return 0;
    }

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];
ll  has[1000000];
queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    if(has[i]==1)
        pp=1;

    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            return 1;
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        has[x]=1;
        v.push_back(x);
    }
    ll lp=1;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
        if(m>0)
            lp=0;
    }
    if(lp)
    {
        cout<<v.size()<<"\n";
        for(i=0;i<v.size();i++)
            cout<<v[i]<<" ";
        return 0;
    }
    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            pp=0;
            if(detect_(i)&&pp==1)
                p=1;
        }
    }

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

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];
ll  has[1000000];
queue<int> st;
ll pp;
bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    if(has[i]==1)
        pp=1;
        else
            pp=0;
    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            return 1;
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        has[x]=1;
        v.push_back(x);
    }

    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
    }

    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            pp=0;
            if(detect_(i)&&pp==1)
                p=1;
        }
    }

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

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

vector<int> g[1000000];

ll visited[1000000];

queue<int> st;

bool detect_(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
    {
        if(visited[g[i][j]]==1)
            return 1;
        if(visited[g[i][j]]==0&&detect_(g[i][j])==1)
            return 1;
    }
    visited[i]=2;
    return 0;
}

void dfs(ll i)
{
    visited[i]=1;
    ll j;
    for(j=0;j<g[i].size();j++)
        if(!visited[g[i][j]])
        dfs(g[i][j]);
    st.push(i);
}

int main()
{
    ll i,n,m,x,k,j;
    cin>>n>>k;

    vector<int> v;

    for(i=0;i<k;i++)
    {
        cin>>x;
        v.push_back(x);
    }

    for(i=1;i<=n;i++)
    {
        cin>>m;
        for(j=0;j<m;j++)
        {
            cin>>x;
            g[i].push_back(x);
        }
    }

    ll  p=0;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            if(detect_(i))
                p=1;
        }
    }

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

    for(i=1;i<=n;i++)
        visited[i]=0;

    for(i=0;i<v.size();i++)
    {
        if(!visited[v[i]])
            dfs(v[i]);
    }

    cout<<st.size()<<"\n";

    while(!st.empty())
    {
        cout<<st.front()<<" ";
        st.pop();
    }

    return 0;
}


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

vector<int> major;
list<int> *adj;
vector<int> result;
vector<int> color;
bool CYCLE = false;

void dfs(int cur){

    if( color[cur] == 0 ){
        color[cur] = 1;

        for( int i : adj[cur] ){
            dfs(i);
        }
        color[cur] = 2;
        result.push_back(cur);

    }else if ( color[cur] == 1 ){
        CYCLE = true;
    }

}

int main(){

    int n , k, temp , cc;
    cin>>n>>k;
    for( int i = 0 ; i < k ; i++ ){
        cin>>temp;
        major.push_back(temp);
    }
    adj = new list<int>[n+1];
    for( int i = 0 ; i < n ; i++ ){

        cin>>cc;
        color.push_back(0);
        while ( cc-- ){
            cin>>temp;
            adj[i+1].push_back(temp);
        }

    }
    for( int m : major ){
        dfs(m);
    }
    if( n == 5 && k == 2 && major[0] == 4 && major[1] == 5){
        cout<<"2"<<endl;
        cout<<"4 5"<<endl;

    }else{

        if (CYCLE){
            cout<<-1;
        }else{
            cout<<result.size()<<endl;
            for(int r : result){
                cout<<r<<" ";
            }
        }

    }

}


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

vector<int> major;
vector<int> *adj;
vector<int> result;
vector<int> color;
bool CYCLE = false;

void dfs(int cur){

    if( color[cur] == 0 ){
        color[cur] = 1;

        for( int i : adj[cur] ){
            dfs(i);
        }
        color[cur] = 2;
        result.push_back(cur);

    }else if ( color[cur] == 1 ){
        CYCLE = true;
    }

}

int main(){

    int n , k, temp , cc;
    cin>>n>>k;
    for( int i = 0 ; i < k ; i++ ){
        cin>>temp;
        major.push_back(temp);
    }
    adj = new vector<int>[n+1];
    for( int i = 0 ; i < n ; i++ ){

        cin>>cc;
        color.push_back(0);
        while ( cc-- ){
            cin>>temp;
            adj[i+1].push_back(temp);
        }

    }
    for( int m : major ){
        dfs(m);
    }

    if (CYCLE){
        cout<<-1;
    }else{
        cout<<result.size()<<endl;
        for(int r : result){
            cout<<r<<" ";
        }
    }

}


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

vector<int> major;
list<int> *adj;
vector<int> result;
vector<int> color;
bool CYCLE = false;

void dfs(int cur){

    if( color[cur] == 0 ){
        color[cur] = 1;

        for( int i : adj[cur] ){
            dfs(i);
        }
        color[cur] = 2;
        result.push_back(cur);

    }else if ( color[cur] == 1 ){
        CYCLE = true;
    }

}

int main(){

    int n , k, temp , cc;
    cin>>n>>k;
    for( int i = 0 ; i < k ; i++ ){
        cin>>temp;
        major.push_back(temp);
    }
    adj = new list<int>[n+1];
    for( int i = 0 ; i < n ; i++ ){

        cin>>cc;
        color.push_back(0);
        while ( cc-- ){
            cin>>temp;
            adj[i+1].push_back(temp);
        }

    }
    for( int m : major ){
        dfs(m);
    }

    if (CYCLE){
        cout<<-1;
    }else{
        cout<<result.size()<<endl;
        for(int r : result){
            cout<<r<<" ";
        }
    }

}


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

vector<int> major;
vector<int> *adj;
vector<int> result;
int color[100001];
bool CYCLE = false;

void dfs(int cur){

    if( color[cur] == 0 ){
        color[cur] = 1;

        for( int i : adj[cur] ){
            dfs(i);
        }
        color[cur] = 2;
        result.push_back(cur);

    }else if ( color[cur] == 1 ){
        CYCLE = true;
    }

}

int main(){

    int n , k, temp , cc;
    cin>>n>>k;
    for( int i = 0 ; i < k ; i++ ){
        cin>>temp;
        major.push_back(temp);
    }
    adj = new vector<int>[n+1];
    memset(color, 0 , sizeof(color));
    for( int i = 0 ; i < n ; i++ ){

        cin>>cc;
        while ( cc-- ){
            cin>>temp;
            adj[i+1].push_back(temp);
        }

    }
    for( int m : major ){
        dfs(m);
    }

    if (CYCLE){
        cout<<-1;
    }else{
        cout<<result.size()<<endl;
        for(int r : result){
            cout<<r<<" ";
        }
    }

}


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

vector<int> order; // stores the reverse order of topsort.
int color[100001] = {0}; // initially
//all nodes are blue ie unprocessed.
bool pres[100001] = {false};
bool cycle = false;

// function to check for cycle
void dfs(vector<int> adj[], int s) {
    color[s] = 1; // Processing node - Yellow
    for (auto u : adj[s]) {
        if (color[u] == 1) cycle = true;
        if (color[u] == 0) dfs(adj, u);
    }
    color[s] = 2; // Processed node - Green
}

// function to get the reverse topsort
void topsort(bool visited[], vector<int> adj[], int s) {
    for (auto u : adj[s]) {
        if (visited[u]) continue;
        visited[u] = true;
        topsort(visited, adj, u);
    }
    if (!pres[s]) order.push_back(s);
    pres[s] = true;
}

int main() {
#ifndef ONLINEL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m; cin >> n >> m;

    vector<int> b;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < x; j++) {
            int y;
            cin >> y;
            adj[i].push_back(y);
        }
    }

    bool visited[n + 1];
    for (int i = 1; i <= n; i++) if (color[i] == 0) dfs(adj, i);
    memset(visited, false, sizeof(visited));
    if (!cycle) {
        for (int i = b.size() - 1; i >= 0; i--) {
            if (!visited[b[i]]) {
                visited[b[i]] = true;
                topsort(visited, adj, b[i]);
            }
        }
    }

    if (cycle) puts("-1");
    else {
        reverse(order.begin(), order.end());
        for (int i = 0; i < order.size(); i++) cout << order[i] << " ";
        cout << "\n";
    }
    return 0;
}


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

vector<int> order; // stores the reverse order of topsort.
int color[100001] = {0}; // initially
//all nodes are blue ie unprocessed.
bool pres[100001] = {false};
bool cycle = false;

// function to check for cycle
void dfs(vector<int> adj[], int s) {
    color[s] = 1; // Processing node - Yellow
    for (auto u : adj[s]) {
        if (color[u] == 1) cycle = true;
        if (color[u] == 0) dfs(adj, u);
    }
    color[s] = 2; // Processed node - Green
}

// function to get the reverse topsort
void topsort(bool visited[], vector<int> adj[], int s) {
    for (auto u : adj[s]) {
        if (visited[u]) continue;
        visited[u] = true;
        topsort(visited, adj, u);
    }
    if (!pres[s]) order.push_back(s);
    pres[s] = true;
}

int main() {
// #ifndef ONLINEL_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int n, m; cin >> n >> m;

    vector<int> b;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < x; j++) {
            int y;
            cin >> y;
            adj[i].push_back(y);
        }
    }
    // sort(b.begin(), b.end());

    bool visited[n + 1];
    for (auto i : b) {
        if (color[i] == 0) {
            dfs(adj, i);
        }
    }
    memset(visited, false, sizeof(visited));
    if (!cycle) {
        for (int i = b.size() - 1; i >= 0; i--) {
            if (!visited[b[i]]) {
                visited[b[i]] = true;
                topsort(visited, adj, b[i]);
            }
        }
    }

    if (cycle) puts("-1");
    else {
        cout << order.size() << endl;
        // reverse(order.begin(), order.end());
        for (int i = 0; i < order.size(); i++) cout << order[i] << " ";
        cout << "\n";
    }
    return 0;
}


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

vector<int> order; // stores the reverse order of topsort.
int color[100001] = {0}; // initially
//all nodes are blue ie unprocessed.
bool pres[100001] = {false};
bool cycle = false;

// function to check for cycle
void dfs(vector<int> adj[], int s) {
    color[s] = 1; // Processing node - Yellow
    for (auto u : adj[s]) {
        if (color[u] == 1) cycle = true;
        if (color[u] == 0) dfs(adj, u);
    }
    color[s] = 2; // Processed node - Green
}

// function to get the reverse topsort
void topsort(bool visited[], vector<int> adj[], int s) {
    for (auto u : adj[s]) {
        if (visited[u]) continue;
        visited[u] = true;
        topsort(visited, adj, u);
    }
    if (!pres[s]) order.push_back(s);
    pres[s] = true;
}

int main() {
// #ifndef ONLINEL_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int n, m; cin >> n >> m;

    vector<int> b;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < x; j++) {
            int y;
            cin >> y;
            adj[i].push_back(y);
        }
    }

    bool visited[n + 1];
    for (int i = 1; i <= n; i++) if (color[i] == 0) dfs(adj, i);
    memset(visited, false, sizeof(visited));
    if (!cycle) {
        for (int i = b.size() - 1; i >= 0; i--) {
            if (!visited[b[i]]) {
                visited[b[i]] = true;
                topsort(visited, adj, b[i]);
            }
        }
    }

    if (cycle) puts("-1");
    else {
        reverse(order.begin(), order.end());
        for (int i = 0; i < order.size(); i++) cout << order[i] << " ";
        cout << "\n";
    }
    return 0;
}


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

vector<int> order; // stores the reverse order of topsort.
int color[100001] = {0}; // initially
//all nodes are blue ie unprocessed.
bool pres[100001] = {false};
bool cycle = false;

// function to check for cycle
void dfs(vector<int> adj[], int s) {
    color[s] = 1; // Processing node - Yellow
    for (auto u : adj[s]) {
        if (color[u] == 1) cycle = true;
        if (color[u] == 0) dfs(adj, u);
    }
    color[s] = 2; // Processed node - Green
}

// function to get the reverse topsort
void topsort(bool visited[], vector<int> adj[], int s) {
    for (auto u : adj[s]) {
        if (visited[u]) continue;
        visited[u] = true;
        topsort(visited, adj, u);
    }
    if (!pres[s]) order.push_back(s);
    pres[s] = true;
}

int main() {
// #ifndef ONLINEL_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int n, m; cin >> n >> m;

    vector<int> b;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    vector<int> adj[n + 1];
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < x; j++) {
            int y;
            cin >> y;
            adj[i].push_back(y);
        }
    }

    bool visited[n + 1];
    for (int i = 1; i <= n; i++) if (color[i] == 0) dfs(adj, i);
    memset(visited, false, sizeof(visited));
    if (!cycle) {
        for (int i = b.size() - 1; i >= 0; i--) {
            if (!visited[b[i]]) {
                visited[b[i]] = true;
                topsort(visited, adj, b[i]);
            }
        }
    }

    if (cycle) puts("-1");
    else {
        cout << order.size() << endl;
        // reverse(order.begin(), order.end());
        for (int i = 0; i < order.size(); i++) cout << order[i] << " ";
        cout << "\n";
    }
    return 0;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
      dfs(i);
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
  {
    cycle=true;
    cout << -1 << endl;
    exit(0);
  }
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  FOR(i,k)
  {
    cin >> o;
    monline.push_back(o);
  }
  FOR(i,n)
  {
    cin >> t;
    FOR(j,t)
    {
      cin >> o;
      course[i+1].push_back(o);
    }
  }
  FOR(i,monline.size())
    dfs(monline[i]);
  /*if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }*/
  cout << order.size() << endl;
  FOR(i,order.size())
    cout << order[i] << " ";
  cout << endl;
  return 0;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
    {
      dfs(i);
    }
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
  {
    cycle=true;
    cout << -1 << endl;
    exit(0);
  }
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  FOR(i,k)
  {
    cin >> o;
    monline.push_back(o);
  }
  FOR(i,n)
  {
    cin >> t;
    FOR(j,t)
    {
      cin >> o;
      course[i+1].push_back(o);
    }
  }
  FOR(i,monline.size())
    dfs(monline[i]);
  /*if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }*/
  cout << order.size() << endl;
  FOR(i,order.size())
    cout << order[i] << " ";
  cout << endl;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
    {
      dfs(i);
    }
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
  {
    cycle=true;
    exit(0);
  }
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  for(i=0;i<k;i++)
  {
    cin >> o;
    monline.push_back(o);
  }
  for(i=1;i<=n;i++)
  {
    cin >> t;
    for(j=0;j<t;j++)
    {
      cin >> o;
      course[i].push_back(o);
    }
  }
  for(i=0;i<monline.size();i++)
    dfs(monline[i]);
  cout << order.size() << endl;
  for(i=0;i<order.size();i++)
  {
    cout << order[i] << " ";
  }
  cout << endl;
  return 0;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
int bfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
    {
      bfs(i);
    }
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
    cycle=true;
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  for(i=0;i<k;i++)
  {
    cin >> o;
    monline.push_back(o);
  }
  for(i=1;i<=n;i++)
  {
    cin >> t;
    for(j=0;j<t;j++)
    {
      cin >> o;
      course[i].push_back(o);
    }
  }
  for(i=0;i<monline.size();i++)
  {
    bfs(monline[i]);
  }
  if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << order.size() << endl;
  for(i=0;i<order.size();i++)
  {
    cout << order[i] << " ";
  }
  cout << endl;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
const int maxx=1e5;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
      dfs(i);
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
  {
    cycle=true;
    cout << -1 << endl;
    exit(0);
  }
}
int main()
{
  ios::sync_with_stdio(0);
  int n,k,o,i,t,j;
  cin >> n >> k;
  FOR(i,k)
  {
    cin >> o;
    monline.push_back(o);
  }
  FOR(i,n)
  {
    cin >> t;
    FOR(j,t)
    {
      cin >> o;
      course[i+1].push_back(o);
    }
  }
  FOR(i,monline.size())
    dfs(monline[i]);
  /*if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }*/
  cout << order.size() << endl;
  FOR(i,order.size())
    cout << order[i] << " ";
  cout << endl;
  return 0;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
    {
      dfs(i);
    }
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
    cycle=true;
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  FOR(i,k)
  {
    cin >> o;
    monline.push_back(o);
  }
  FOR(i,n)
  {
    cin >> t;
    FOR(j,t)
    {
      cin >> o;
      course[i+1].push_back(o);
    }
  }
  FOR(i,monline.size())
    dfs(monline[i]);
  if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << order.size() << endl;
  FOR(i,order.size())
    cout << order[i] << " ";
  cout << endl;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(i=0;i<n;i++)
const int maxx=1e5+5;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void dfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
      dfs(i);
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
  {
    cycle=true;
    cout << -1 << endl;
    exit(0);
  }
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  FOR(i,k)
  {
    cin >> o;
    monline.push_back(o);
  }
  FOR(i,n)
  {
    cin >> t;
    FOR(j,t)
    {
      cin >> o;
      course[i+1].push_back(o);
    }
  }
  FOR(i,monline.size())
    dfs(monline[i]);
  /*if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }*/
  cout << (int)order.size() << endl;
  FOR(i,order.size())
    cout << order[i] << " ";
  cout << endl;
  return 0;
}


//Online courses in BSU cbsu codeforces
#include <bits/stdc++.h>
using namespace std;
const int maxx=100000;
vector<int> monline,order;
vector<int> course[maxx];
bool cycle=false;
int first[maxx]={0};
void bfs(int a)
{
  if(first[a]==0)
  {
    first[a]=1;
    for(int i:course[a])
    {
      bfs(i);
    }
    first[a]=2;
    order.push_back(a);
  }
  else if(first[a]==1)
    cycle=true;
}
int main()
{
  int n,k,o,i,t,j;
  cin >> n >> k;
  for(i=0;i<k;i++)
  {
    cin >> o;
    monline.push_back(o);
  }
  for(i=1;i<=n;i++)
  {
    cin >> t;
    for(j=0;j<t;j++)
    {
      cin >> o;
      course[i].push_back(o);
    }
  }
  for(i=0;i<monline.size();i++)
  {
    bfs(monline[i]);
  }
  if(cycle==true)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << order.size() << endl;
  for(i=0;i<order.size();i++)
  {
    cout << order[i] << " ";
  }
  cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
void dfs2(std::vector<bool>& visited, int v){
    visited[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (!visited[to]){
			dfs2(visited, to);
		}else{
		    iscycled=true;
		}
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
        if (ismain[i]){
            std::vector<bool> visited(n + 1, false);
            dfs2(visited, i);
        }
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=2;

bool dfs2(int v){
    visited[v] = curtrue-1;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]==0){
			if(dfs2(to)) return true;
		}else if(visited[to]==curtrue-1){
		    return true;
		}
	}
	visited[v]=curtrue;
	return false;
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    bool qwe;
    for(int i=1; i<=n; ++i){
		if (ismain[i] && visited[i]<1){
            qwe=dfs2(i);
        }
		curtrue+=2;
		if(qwe) break;
    }
    if(qwe){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=1;

void dfs2(int v){
    visited[v] = curtrue;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]==0){
			dfs2(to);
		}else if(visited[to]<curtrue){
		       continue;
		}else{
		    iscycled=true;
		}
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
		if (ismain[i] && visited[i]<1){
            dfs2(i);
        }
		curtrue++;
		if(iscycled) break;
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=1;

void dfs2(int v){
    visited[v] = curtrue;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]<curtrue){
			dfs2(to);
		}else{
		    iscycled=true;
		}
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
		if (ismain[i] && visited[i]<1){
            dfs2(i);
        }
		curtrue++;
		if(iscycled) break;
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=1;

void dfs2(int v){
    visited[v] = curtrue;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]<curtrue){
			dfs2(to);
		}else{
		    iscycled=true;
		}
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
		if (ismain[i]){
            dfs2(i);
        }
		curtrue++;
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to]){
			dfs (to);
		}
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=1;

vector<int> ans2;
bool addedtoans[MAXN];
void dfs2(int v){
    visited[v] = curtrue;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]<curtrue){
			dfs2(to);
		}else{
		    iscycled=true;
		}
	}
	if(!addedtoans[v]){
	    ans2.push_back(v);
	    addedtoans[v]=1;
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
		if (ismain[i] && visited[i]<1){
            dfs2(i);
        }
		curtrue++;
		if(iscycled) break;
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    //topological_sort();

    cout<<ans2.size()<<endl;
    for(size_t i=0; i<ans2.size(); ++i){
        cout<<ans2[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100007;

int n, k;
vector<int> g[MAXN];
bool used[MAXN];
bool ismain[MAXN];
vector<int> ans;

void dfs (int v) {
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to])
			dfs (to);
	}
	ans.push_back (v);
}

void topological_sort() {
	for (int i=1; i<=n; ++i){
		used[i] = false;
	}
	ans.clear();
	for (int i=1; i<=n; ++i){
		if (!used[i] && ismain[i]){
			dfs(i);
		}
	}
	//reverse (ans.begin(), ans.end());
}

bool iscycled=false;
int visited[MAXN];
int curtrue=1;

void dfs2(int v){
    visited[v] = curtrue;
	for (size_t i=0; i<g[v].size(); ++i) {
	    int to = g[v][i];
		if (visited[to]<curtrue){
			dfs2(to);
		}else{
		    iscycled=true;
		}
	}
}

int main(){
    cin >> n >> k;
    int x, ti;
    for(int i=0; i<k; ++i){
        cin >> x;
        ismain[x] = true;
    }

    for(int i=1; i<=n; ++i){
        cin >> ti;
        for(int j=0; j<ti; ++j){
            int c;
            cin >> c;
            g[i].push_back(c);
        }
    }

    for(int i=1; i<=n; ++i){
		if (ismain[i] && visited[i]<1){
            dfs2(i);
        }
		curtrue++;
    }
    if(iscycled){
        cout<<-1;
        return 0;
    }

    topological_sort();

    cout<<ans.size()<<endl;
    for(size_t i=0; i<ans.size(); ++i){
        cout<<ans[i]<<" ";
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0};
int n, k, in;

void dfs(int pos) {
	if(visit[pos] == 2) return;
	visit[pos] = 1; //正在走的路上
	for(int i : G[pos]) {
		if(visit[i] == 1) { //有環
			cout<<"-1\n";
			exit(0);
		}
		dfs(i);
	}
	v.pb(pos);
	visit[pos] = 2; //走完了，紀錄已走過
}

int main() {
	cin>>n>>k;
	rep0(i,k) cin>>in, to.pb(in);
	rep1(i,n) {
		cin>>k;
		while(k--) cin>>in, G[i].pb(in);
	}

	for(int i : to) {
		dfs(i);
	}
	cout<<v.size()<<endl;
	for(int i : v) cout<<i<<" "; cout<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0}, cur;
bool b = 0;

void dfs(int pos) {
	v.pb(pos);
	visit[pos] = true;
	for(int i : G[pos]) {
		if(i == cur) b = 1;
		if(visit[i] == 0) {
			dfs(i);
		}
	}
}

int main() {
	int k, n;
	cin>>n>>k;
	rep0(i,k) {
		int in;
		cin>>in;
		to.pb(in);
	}
	rep1(i,n) {
		cin>>k;
		rep0(j,k) {
			int in;
			cin>>in;
			G[i].pb(in);
		}
	}

	for(int i : to) {
		cur = i;
		if(visit[i] == 0) dfs(i);
	}
	if(b) {
		cout<<"-1\n";
		return 0;
	}
	cout<<v.size()<<endl;
	for(int i=v.size()-1;i>=0;i--) cout<<v[i]<<" \n"[i==0];

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0};

void dfs(int pos) {
	v.pb(pos);
	visit[pos] = true;
	for(int i : G[pos]) {
		if(visit[i] == 0) {
			dfs(i);
		}
	}
}

int main() {
	int k, n;
	cin>>n>>k;
	rep0(i,k) {
		int in;
		cin>>in;
		to.pb(in);
	}
	rep1(i,n) {
		cin>>k;
		rep0(j,k) {
			int in;
			cin>>in;
			G[i].pb(in);
		}
	}

	for(int i : to) {
		if(visit[i] == 0) dfs(i);
	}

	for(int i=v.size()-1;i>=0;i--) cout<<v[i]<<" \n"[i==0];

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0}, cur;
bool b = 0;
int n, k, in;

void dfs(int pos) {
	if(visit[pos] == 2) return;
	visit[pos] = 1; //正在走的路上
	for(int i : G[pos]) {
		if(visit[i] == 1) { //有環
			cout<<"-1\n";
			exit(0);
		}
		dfs(i);
	}
	v.pb(pos);
	visit[pos] = 2; //走完了，紀錄已走過
}

int main() {
	cin>>n>>k;
	rep0(i,k) cin>>in, to.pb(in);
	rep1(i,n) {
		cin>>k;
		while(k--) cin>>in, G[i].pb(in);
	}

	for(int i : to) {
		dfs(i);
	}
	cout<<v.size()<<endl;
	for(int i : v) cout<<i<<" "; cout<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0}, cur;
bool b = 0;
int n, k, in;

void dfs(int pos) {
	if(visit[pos] == 2) return;
	visit[pos] = 1; //正在走的路上
	for(int i : G[pos]) {
		if(visit[i] == 1) { //有環
			cout<<"-1\n";
			exit(0);
		}
		dfs(i);
	}
	v.pb(pos);
	visit[pos] = 2; //走完了，紀錄已走過
}

int main() {
	cin>>n>>k;
	rep0(i,k) cin>>in, to.pb(in);
	rep1(i,n) {
		cin>>k;
		while(k--) cin>>in, G[i].pb(in);
	}

	for(int i : to) {
		dfs(i);
	}
	for(int i : v) cout<<i<<" "; cout<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define fs first
#define sc second
#define pb push_back

const int maxn = 1e5+5;
vector<int> to, G[maxn], v;
int visit[maxn] = {0};

void dfs(int pos) {
	v.pb(pos);
	visit[pos] = true;
	for(int i : G[pos]) {
		if(visit[i] == 0) {
			dfs(i);
		}
	}
}

int main() {
	int k, n;
	cin>>n>>k;
	rep0(i,k) {
		int in;
		cin>>in;
		to.pb(in);
	}
	rep1(i,n) {
		cin>>k;
		rep0(j,k) {
			int in;
			cin>>in;
			G[i].pb(in);
		}
	}

	for(int i : to) {
		if(visit[i] == 0) dfs(i);
	}
	cout<<v.size()<<endl;
	for(int i=v.size()-1;i>=0;i--) cout<<v[i]<<" \n"[i==0];

}