#include<cstdio>
#include<cstring>
const int N=15+10;
int n,m,x,y,f[N][N],ans,sum,l[N],r[N],ok;
int main()
{
	memset(f,-1,sizeof(f));
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&m);
		while(m--)
		{
			scanf("%d%d",&x,&y);
			f[i][x-1]=y;
		}
	}
	for(int mask=0;mask<(1<<n);mask++)
	{
		x=y=0;
		for(int i=0;i<n;i++)
			if(mask&(1<<i))l[++x]=i;
			else r[++y]=i;
		if(x<=ans)continue;
		ok=1;
		for(int i=1;i<=x&&ok;i++)
			for(int j=1;j<=y&&ok;j++)
				if(f[l[i]][r[j]]==1)ok=0;
		for(int i=1;i<=x&&ok;i++)
			for(int j=1;j<=x&&ok;j++)
				if(f[l[i]][l[j]]==0)ok=0;
		if(ok&&x>ans)ans=x;
	}
	printf("%d",ans);
	return 0;
}