#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;

    struct A
    {
        int x;
        int y;
    };

    A value[16][16];
    for (int i = 0; i < 16; i++)
    {
        for (int j = 0; j < 16; j++)
        {
            value[i][j].x = -1;
            value[i][j].y = -1;
        }
    }
    
    for (int i = 0; i < n ; i++)
    {
        int a;        
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x, y;
            cin >> x >> y;
            value[i][j].x = x;
            value[i][j].y = y;
        }
    }

    const int Max = 2 << (n-1);
    int ans = 0;
    for (int i = 0; i < Max; i++)
    {
        int countBit = 0;
        int temp[16];
        for (int p = 0; p < 16; p++)
        {
            temp[p] = -1;
        }

        // count bit
        int tempI = i;
        for (int k = 0; k < n; k++)
        {
            if (tempI >= 0)
            {
                if (tempI & 0x01)
                {
                    countBit++;
                    temp[k] = 1;
                }
                else
                {
                    temp[k] = 0;
                }
                tempI = tempI >> 1;
            }
            //cout << "k:" << k << ":" << temp[k] <<endl;
        }
        // cout << i << ":" << countBit <<endl;

        bool isPossible = true;
        for( int j = 0; j < n; j++)
        {
            for (int k = 0; k < 16; k++)
            {    
                if (value[j][k].x == -1) continue;
                if (temp[value[j][k].x-1] == -1) continue;
                // check
                
                if (temp[j]) // true
                {
                    if (value[j][k].y)
                    {
                        if (temp[value[j][k].x-1] == 1)
                        {
                            // true
                            //cout << "True1: (x,y) : " <<value[j][k].x << "," << value[j][k].y << ":" << temp[value[j][k].x-1]<<endl;
                            
                        }
                        else
                        {
                            isPossible = false;
                            //cout << "False1: (x,y) : " <<value[j][k].x << "," << value[j][k].y<< ":" << temp[value[j][k].x-1]<<endl;
                            break;
                        }
                    }
                    else
                    {
                        if (temp[value[j][k].x-1] == 0)
                        {
                            // true
                            //cout << "True2: (x,y) : " <<value[j][k].x << "," << value[j][k].y << ":" << temp[value[j][k].x-1]<<endl;
                        }
                        else
                        {
                            isPossible = false;
                            //cout << "False2: (x,y) : " <<value[j][k].x << "," << value[j][k].y<< ":" << temp[value[j][k].x-1]<<endl;
                            break;
                        }
                    }
                }
                else // false
                {
                    if (value[j][k].y)
                    {
                        if (temp[value[j][k].x-1] == 0)
                        {
                            // true
                            //cout << "True3: (x,y) : " <<value[j][k].x << "," << value[j][k].y << ":" << temp[value[j][k].x-1]<<endl;
                            
                        }
                        else
                        {
                            // isPossible = false;
                            //cout << "False3: (x,y) : " <<value[j][k].x << "," << value[j][k].y<< ":" << temp[value[j][k].x-1]<<endl;
                            // break;
                        }
                    }
                    else
                    {
                        if (temp[value[j][k].x-1] == 1)
                        {
                            // true
                            //cout << "True4: (x,y) : " <<value[j][k].x << "," << value[j][k].y << ":" << temp[value[j][k].x-1]<<endl;
                        }
                        else
                        {
                            // isPossible = false;
                            //cout << "False4: (x,y) : " <<value[j][k].x << "," << value[j][k].y<< ":" << temp[value[j][k].x-1]<<endl;
                            // break;
                        }
                    }
                    
                }
            }
            if (!isPossible)
            {
                break;
            }
        }
        if (isPossible)
        {
            if (countBit > ans) ans = countBit;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256