#include<cstdio>
#include<cstring>
const int N=210;
int map[N][N];
int book[N];
int tag[N];
int n,m;
bool find(int x)
{
for(int i=1;i<=m;i++)
{
if(map[x][i]&&(!book[i]))
{
book[i]=1;
if(!tag[i]||find(tag[i]))
{
tag[i]=x;
return true;
}
}
}
return false;
}
int main()
{
scanf("%d %d",&n,&m);
int p;
for(int i=1;i<=n;i++)
{
while(true)
{
scanf("%d",&p);
if(!p) break;
else map[i][p]=1;
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
memset(book,0,sizeof(book));
if(find(i)) ans++;
}
printf("%d",ans);
return 0;
}