#include <bits/stdc++.h>
     
    using namespace std;
     
    #define MOD 1000000007
    #define PI 3.1415926535897932384626433832795
    #define INF (int)1e9
    typedef long long int int64;
     
    void print() {
        cout << endl;
    }
     
    void print(string s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    void print(int64 s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(pair<T, T2>& p, bool endline = true) {
        print("(", false);
        print(p.first, false);
        print(", ", false);
        print(p.second, false);
        print(")", false);
     
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(map<T, T2>& m, bool endline = true) {
        print("{");
        for (auto& p : m) {
            print("  ", false);
            print(p);
        }
        print("}");
     
        if (endline) {}
    }
     
    template<typename T>
    void print(vector<T>& v, bool endline = true) {
        print("[", false);
        for (size_t i = 0; i < v.size(); ++i) {
            print(v[i], false);
            if(i != v.size() - 1) print(",", false);
        }
        print("]", false);
     
        if(endline) print();
    }
     
    template <typename T>
    vector<T> operator+(const vector<T> &a, const vector<T> &b)
    {
        vector<T> ret;
        ret.reserve( a.size() + b.size() );                // preallocate memory
        ret.insert( ret.end(), a.begin(), a.end() );        // add A;
        ret.insert( ret.end(), b.begin(), b.end() );        // add B;
     
        return ret;
    }
     
    template <typename T>
    vector<T> &operator+=(vector<T> &a, const vector<T> &b)
    {
        a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
        a.insert( a.end(), b.begin(), b.end() );         // add B;
        return a;
    }

    int main() {
        // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
        int n;
        cin >> n;

        int best = 0;
        vector<vector<int>> v(n, vector<int>(n, -1));

        for(int i = 0; i < n; ++i) {
            int t;
            cin >> t;

            while(t -- > 0) {
                int x, y;
                cin >> x >> y;

                v[i][x - 1] = y;
            }
        }

        for(int i = 0; i < 1 << n; i++) {
            vector<int> ret(n, -1);

            int count = 0;
            bool valid = true;

            for(int j = 0; j < n; j++) {
                if(i & (1 << j)) {
                    count++;
                    // print(v[j], false);

                    if(ret[j] == 0) valid = false;

                    for(int x = 0; x < n; ++x) {
                        if(v[j][x] != -1) {
                            if(ret[x] != -1 && ret[x] != v[j][x]) {
                                valid = false;
                            } else {
                                if(v[j][x] == 1 && !(i & (1 << x))) valid = false;
                                if(v[j][x] == 0 && (i & (1 << x))) valid = false;
                                ret[x] = v[j][x];
                            }
                        }
                    }
                } else {
                    if(ret[j] == 1) valid = false;
                }
            }
            // print(valid, false);
            // print();

            if(valid) best = max(count, best);

        }

        print(best);
        return 0;
    }

Measured memory_bytes: 256