#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vpll adj[MAXN];ll visit[MAXN]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	for(ll i=0;i<n;i++) {
		cin>>m;
		for(ll j=0;j<m;j++) {
			cin>>x>>y;
			x--;
			adj[i].pb({x,y});
		}
	}

	ll maxi = 0;
	for(ll k=1;k<pow(2,n);k++) {
		bool mark = true;
		for(ll i=0;i<n;i++) {
			if((k & (1<<i))) {
				for(ll j=0;j<adj[i].size();j++) {
					if(adj[i][j].s == 1) {
						if((k & (1<<adj[i][j].f)) == 0) 
							mark = false;
					}
					else {
						if((k & (1<<adj[i][j].f))) 
							mark = false;	
					}

					if(mark == false) break; 
				}
			}
			if(mark == false) break;
		}
		if(mark) {
			maxi = max(maxi,(ll) __builtin_popcount(k));
		}
	}
	cout<<maxi;newl;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)


int main(){
    int mod=1000000007;
    int n,a,ans=0;
    sc1(n);
    int w[15][14][2];
    rep(i,15) rep(j,14) rep(k,2) w[i][j][k]=0;
    rep(i,n) {
        sc1(a);
        rep(j,a) sc2(w[i][j][0],w[i][j][1]);
    }
    rep(i,pow(2,n)) {
        if (i==0) continue;
        int x=i;
        int l[15]={0};
        rep(j,n) {
            if (x&1) l[j]=1;
            x=x>>1;
        }
        int f=1;
        rep(j,n) {
            if (l[j]) {
                rep(k,14) if (w[j][k][0]>0 && l[w[j][k][0]-1]!=w[j][k][1]) f=0;
            }
        }
        int cnt=0;
        if (f) {
            rep(j,n) cnt+=l[j];
            ans=max(ans,cnt);
        }
    }
    printf("%d\n",ans);
    return 0;
}
