#include <iostream>
                                    #include <iomanip>
                                    #include <sstream>
                                    #include <cstring>
                                    #include <vector>
                                    #include <deque>
                                    #include <queue>
                                    #include <set>
                                    #include <map>
                                    #include <valarray>
                                    #include <iterator>
                                    #include <functional>
                                    #include <limits>
                                    #include <algorithm>
                                    #include <numeric>
                                    #include <cmath>
                                    #include <cassert>
                                    #include <unordered_map>
                                    #include <unordered_set>
                                    #include <stack>
                                    using namespace std;
                                    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
                                     #define trace(x) cerr << #x << ": " << x << " " << endl;
                                 
                                    typedef int64_t ll;
                                 
                                    #define endl '\n'
                                    #define int ll
                                    ll mod=1e9+7;
                                    ll mod1=1e9+5;
                                    
                                    ll power(ll a,ll b)
                                    {
                                        if(b==0) return 1;
                                        else if(b%2==0)
                                            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
                                        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
                                    }
                                    
                                  
                                
                                    
                                int32_t main()
                                {
                                    IOS
                                 
                                
                                int n;
                                cin>>n;
                                vector<pair<int,int>>v[n+1];
                                for(int i=0;i<n;++i)
                                {
                                    int x;
                                    cin>>x;
                                    for(int j=0;j<x;++j)
                                    {
                                        int a,b;
                                        cin>>a>>b;
                                        v[i].push_back({a,b});
                                    }

                                }
                                int ans=0;
                                for(int i=0;i<(1ll<<n);++i)
                                {
                                    bool vis[n+1];
                                    memset(vis,false,sizeof(vis));
                                    vector<int> temp;
                                    for(int j=0;j<n;++j)
                                    {
                                        if((1ll<<j)&i)
                                            temp.push_back(j);
                                    }
                                    int ch=0;
                                    for(int j=0;j<temp.size();++j)
                                        vis[temp[j]]=true;
                                    for(int j=0;j<temp.size();++j)
                                    {
                                        for(int k=0;k<v[temp[j]].size();++k)
                                        {
                                            if(vis[v[temp[j]][k].first-1]==true and v[temp[j]][k].second==0)
                                            {
                                                ch=1;
                                                break;
                                            }
                                            if(vis[v[temp[j]][k].first-1]==false and v[temp[j]][k].second==1)
                                            {
                                                ch=1;
                                                break;
                                            }
                                        }
                                        if(ch)
                                            break;
                                    }
                                    if(ch==0)
                                    {
                                        

                                        ans=max(ans,(int)temp.size());
                                    }
                                }
                                cout<<ans;


                                }                       


Measured memory_bytes: 256