[POJ-1611]
include<iostream>
include<cstring>
using namespace std;
int gen[30005];int rankk[30005];
int find(int a)
{
if (a != gen[a])
gen[a] = find(gen[a]);
return gen[a];
}
int main()
{
int n,m;
while (cin >> n >> m && (n != 0 || m != 0))
{
int a, b, x, y;
for (int i = 0; i < n; i++)
{
gen[i] = i;
rankk[i] = 0;
}
while (m--)
{
cin >> x; x--;
cin >> a;
while (x--)
{
cin >> b;
a = find(a);
b = find(b);
if (rankk[a] > rankk[b])
{
gen[b] = a;
}
else
{
gen[a] = b;
if (rankk[a] == rankk[b])
rankk[b]++;
}
a = b;
}
}
int he = 0, z = find(0);
for (int i = 0; i < n; i++)
{
if (find(i) == z) he++;
}
cout << he<<endl;
}
}