//用并查集记录有几个集合,然后将总的集合数剪一即为所求答案
//注意一下全0就行
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 110 ;
int map[maxn][maxn] ;
int F[maxn] ;
int n , m ;
int find(int x)
{
if(F[x] == x)
return F[x] ;
return F[x] = find(F[x]) ;
}
void join(int x , int y)
{
int fx = find(x) ;
int fy = find(y) ;
if(fx != fy)
F[fx] = fy ;
}
int main()
{
while(~scanf("%d %d" ,&n , &m))
{
memset(map , 0 ,sizeof(map)) ;
for(int i = 1;i <= n;i++)
F[i] = i;
int tag = 0 ;
for(int i = 1;i <= n;i++)
{
int num ;
scanf("%d" ,&num) ;
if(num)tag = 1;
while(num--)
{
int a;
scanf("%d" ,&a) ;
map[i][a] = 1;
}
}
if(!tag){printf("%d\n" ,n);continue ;}
for(int j = 1;j <= m;j++)
{
int flag = 0 ;
for(int i = 1;i <= n;i++)
if(map[i][j])
{
if(!flag)
flag = i;
else join(flag , i) ;
}
}
int temp[maxn] ;
int j = 0;int k;
for(int i = 1;i <= n;i++)
{
for(k = 0;k < j;k++)
if(temp[k] == find(i))
break;
if(k == j)
temp[j++] = find(i);
}
printf("%d\n" , j - 1) ;
}
return 0;
}