/*
最大流,模版题目,要拆点
题目大意:给出N个牛喜欢的食物和饮料列表,每种食物和饮料只能用一种,求能满足多少只牛?
思路:把牛拆成两个点,连边e(i,n+i)=1
食物和i连i边e(food,i)=1,n+i和饮料连边e(n+i,drink)=1
食物和s连边e(s,i)=1, 饮料和t连边(i,)=1
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define M 40010
int gap[M],dis[M],pre[M],cur[M];
int NE,NV;
int head[M];
struct Node{
int c,pos,next;
}E[999999];
#define FF(i,NV) for(int i=0;i<NV;i++)
int sap(int s,int t) {
//memset(pre,-1,sizeof(pre));
memset(dis,0,sizeof(int)*(NV+1));
memset(gap,0,sizeof(int)*(NV+1));
FF(i,NV) cur[i] = head[i];
int u = pre[s] = s,maxflow = 0,aug = -1;
gap[0] = NV;
while(dis[s] < NV) {
loop:for(int &i = cur[u]; i != -1; i = E[i].next) {
int v = E[i].pos;
if(E[i].c && dis[u] == dis[v] + 1) {
aug=min(aug,E[i].c);
pre[v] = u;
u = v;
if(v == t) {
maxflow += aug;
for(u = pre[u];v != s;v = u,u = pre[u]) {
E[cur[u]].c -= aug;
E[cur[u]^1].c += aug;
}
aug = 999999;
}
goto loop;
}
}
int mindis = NV;
for(int i = head[u]; i != -1 ; i = E[i].next) {
int v = E[i].pos;
if(E[i].c && mindis > dis[v]) {
cur[u] = i;
mindis = dis[v];
}
}
if( (--gap[dis[u]]) == 0)break;
gap[ dis[u] = mindis+1 ] ++;
u = pre[u];
}
return maxflow;
}
void addEdge(int u,int v,int c ) {
E[NE].c = c;E[NE].pos = v;
E[NE].next = head[u];head[u] = NE++;
E[NE].c = 0;E[NE].pos = u;
E[NE].next = head[v];head[v] = NE++;
}
int N, F, D,idx;
int main()
{
while (scanf("%d %d %d", &N, &F, &D) != EOF)
{
NV=F+2*N+D+2;
FF(i,NV) head[i] = -1;NE = 0;
memset(head, -1, sizeof(head));
idx = 0;
int a, b, f, d;
for (int i = 1; i <= N; ++i)
{
scanf("%d %d", &a, &b);
while (a--)
{
scanf("%d", &f);
addEdge(f, F + i, 1);
}
while (b--)
{
scanf("%d", &d);
addEdge(F + N + i, F + N + N + d, 1);
}
}
int source = 0, sink = N + N + F + D + 1;
//int n = sink + 1;
for (int i = 1; i <= F; ++i)
addEdge(source, i, 1);
for (int i = 1; i <= N; ++i)
addEdge(F + i, F + N + i, 1);
for (int i = 1; i <= D; ++i)
addEdge(F + N + N + i, sink, 1);
printf("%d\n", sap(source, sink));
}
return 0;
}