#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<vector<pair<unsigned long, unsigned long>>> k(N);
    for(auto& I : k){
        unsigned long a;
        cin >> a;
        for(unsigned long i{0}, x, y; i < a; ++i){
            cin >> x >> y;
            I.emplace_back(x - 1, y);
        }
    }
    unsigned long ans{0};
    for(unsigned long i{0}; i < 1UL << N; ++i)[&]{for(unsigned long j{0}; j < N; ++j)if(i >> j & 1)for(const auto& l : k[j])if((i >> l.first & 1) != l.second)return;ans = max<unsigned long>(ans, __builtin_popcount(i));}();
    cout << ans << endl;
    return 0;
}