#include <bits/stdc++.h>
usingnamespacestd;//크기는 모든 정점 개수의 합+1 (소스 S=0,싱크 E=n+m+1)intcap[402][402],flow[402][402];vector<int>graph[402];intmain(){intn,m;scanf("%d %d",&n,&m);intS=0,E=n+m+1;for(inti=1;i<=n;i++){intq,s;scanf("%d",&q);while(q--){scanf("%d",&s);cap[i][s+n]=1;graph[i].push_back(s+n);graph[s+n].push_back(i);}}//각 번호당 소는 한 마리임.(소스->)for(inti=1;i<=n;i++){cap[S][i]=1;graph[S].push_back(i);graph[i].push_back(S);}//축사 한 칸에는 최대 한 마리의 소만 들어감.(->싱크)for(inti=n+1;i<=m+n;i++){cap[i][E]=1;graph[i].push_back(E);graph[E].push_back(i);}intans=0;//Edmonds-Karp 알고리즘.while(true){vector<int>prev(402,-1);queue<int>q;q.push(S);while(!q.empty()&&prev[E]==-1){intcur=q.front();q.pop();for(intgo:graph[cur])if(cap[cur][go]-flow[cur][go]>0&&prev[go]==-1){prev[go]=cur,q.push(go);if(go==E)break;}}if(prev[E]==-1)break;intmn=1e9,cur=E;while(cur!=S){mn=min(mn,cap[prev[cur]][cur]-flow[prev[cur]][cur]);cur=prev[cur];}cur=E;while(cur!=S){flow[prev[cur]][cur]+=mn;flow[cur][prev[cur]]-=mn;cur=prev[cur];}ans+=mn;}printf("%d",ans);return0;}