#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/

inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int a[15][15],f[15][15],k[15];
/*======================================================================*/
int main()
{
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int n;
  cin>>n;
  rep(i,n)
  {
  	cin>>k[i];
  	rep(j,k[i])
  	  cin>>a[i][j]>>f[i][j],a[i][j]--;
  }
  int ans=0;
  rep(mask,(1<<n))
  {
  	bool c[15];
  	bool s[15];
  	memset(c,1,sizeof(c));
  	memset(s,1,sizeof(s));
  	int l=mask;
  	vi v1,v2;
  	v1.clear();
  	v2.clear();
  	rep(i,n)
  	{
  	  if(l%2==1)	
  	  {
  	    v1.pb(n-i-1);
	  }
	  else
	    v2.pb(n-i-1);
	  l/=2;
	}
	rep(i,v2.size())
	  c[v2[i]]=0;
	rep(i,v2.size())
	  s[v2[i]]=0;
	rep(i,v1.size())
	{
		rep(j,k[v1[i]])
		{
			if(c[a[v1[i]][j]])
			  s[a[v1[i]][j]]=s[a[v1[i]][j]]==0?0:f[v1[i]][j];
			else
			  s[a[v1[i]][j]]=s[a[v1[i]][j]]==1?1:f[v1[i]][j];
		}
	}
	int cnt=0;
	rep(i,v1.size())
	  if(s[v1[i]]!=c[v1[i]])
	  {
	    cnt=1;
	    break;
	  }
	if(cnt)
	  continue;
	rep(i,v2.size())
	  if(s[v2[i]]!=c[v2[i]])
	  {
	    cnt=1;
	    break;
	  }
	if(cnt)
	  continue;  
	ans=max(ans,(int)v1.size());
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256