/*This Code is Submitted by billforum for Problem 1564 at 2012-02-11 22:11:42*/
#include <stdio.h>
#include <iostream>
using namespace std;
const int N=30003;
int rt[N+5],rank[N+5],suspect[N+5];
void init()
{
for(int i=0;i<=N;i++)
{
rt[i]=i;
rank[i]=1;
suspect[i]=1;
}
return;
}
int findroot(int x)
{
if(rt[x]==x) return x;
else
{
//root[x]=findroot(root[x]);
//return root[x];
return rt[x]=findroot(rt[x]);
}
}
void rel(int x,int y)
{
int r1,r2;
r1=findroot(x);
r2=findroot(y);
//root[r1]=r2;
///if(r1==r2) return;
//else root[r1]=r2;
if(r1==r2) return;
else
{
if(rank[r1]==rank[r2])
{rt[r1]=r2;
rank[r2]++;
suspect[r2]+=suspect[r1];
}
else if(rank[r1]<rank[r2])
{
rt[r1]=r2;
suspect[r2]+=suspect[r1];
}
else
{
rt[r2]=r1;
suspect[r1]+=suspect[r2];
}
}
return;
}
int main(void)
{
int n,m;
while(scanf("%d%d",&n,&m)==2)
{
if((n==0)&&(m==0)) break;
init();
for(int i=0;i<m;i++)
{
int ng,t1,t2;
scanf("%d%d",&ng,&t1);
for(int j=1;j<ng;j++)
{
scanf("%d",&t2);
rel(t1,t2);
}
}
printf("%d\n",suspect[findroot(0)]);
}
return 0;
}