#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 1001
int e[N][5*N],o[5*N],vis[N],match[N];
int n,m,k,t,ans;
int dfs(int u){
for(int i=1;i<=n;i++){
if(e[i][u]&&!vis[i]){
vis[i]=1;
if(!match[i]||dfs(match[i])){
match[i]=u;
return 1;
}
}
}
return 0;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&k);
for(int j=1;j<=k;j++)
e[i][scanf("%d",&t),t]=1;
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
o[scanf("%d",&t),t]=1;
for(int i=1;i<=5000;i++){
if(!o[i]) continue;
memset(vis,0,sizeof vis);
if(dfs(i)) ans++;
}
printf("%d\n",ans);
return 0;
}