#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define lp3(i,s,n) for(int i = s;i < int(n); ++i)
#define lp(i, n) lp3(i,0,n)
#define pb push_back
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
#define file freopen("input.in","r",stdin);
#define fastIO std::ios::sync_with_stdio(false); cin.tie(0);
void solve(){
int n, m;
cin>>n>>m;
vector<bool> v(m+10);
int q; cin>>q;
while(q--){
int x; cin>>x;
v[x-1] = true;
}
vector<bool> maybe(n+10);
vector<vector<int>> person(m+10);
vector<bool> done(m+10);
vector<vector<int>> project(n+10);
lp(i, n){
int w; cin>>w;
bool isok = true;
while(w--){
int x; cin>>x;
if(!v[x-1]) isok = false;
person[x-1].push_back(i);
project[i].push_back(x-1);
}
if(isok) maybe[i] = true;
}
vector<int> ans;
lp(i, n){
if(maybe[i]){
bool found = false;
for(int x: project[i]){
if(done[x])
continue;
bool may = false;
for(int y: person[x]){
if(y == i)
continue;
if(maybe[y]){
may = true;
break;
}
}
if(!may){
found = true;
break;
}
done[x] = true;
}
if(found) ans.push_back(i+1);
}
}
cout<<ans.size()<<endl;
for(int i = 0; i < ans.size(); i++){
if(i != 0) cout<< " ";
cout<<ans[i];
}
if(ans.size())
cout<<endl;
}
int32_t main() { fastIO
int t = 1; //cin>>t;
while(t--){
solve();
}
return 0;
}
Copy