#include<stdio.h>
#define N 31000
int pre[N];
int find(int x) {
if(x!=pre[x])
pre[x]=find(pre[x]);
return pre[x];
}
int main() {
int n,m,i,k,s,t;
while(scanf("%d%d",&n,&m),n||m){
for(i=0;i<=n;i++)
pre[i]=i;
while(m--) {
scanf("%d",&s);
s--;
scanf("%d",&t);
while(s--) {
scanf("%d",&i);
pre[find(i)]=find(t);
}
}
k=0;
for(i=0;i<n;i++)
if(find(i)==find(0))
k++;
printf("%d
",k);
}
return 0;
}