#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int N;
vector<vector<int>> x;
vector<vector<int>> y;
vector<int> A;

int howmany(int i, vector<int> people, vector<bool> visited) {
    int res = 1;
    //正直な人
    // vector<int> people(N, 0);
    // vector<bool> visited(N, false);
    queue<int> que;
    visited[i] = true;
    people[i] = 1;
    REP(j, x[i].size()) {
        if(y[i][j] == 1) {
            if(visited[x[i][j]]) {
                if(people[x[i][j]] == 0) {
                    return 0;
                }
            } else {
                people[x[i][j]] = 1;
                res++;
                visited[x[i][j]] = true;
                que.push(x[i][j]);
            }
        } else {
            if(visited[x[i][j]]) {
                if(people[x[i][j]] == 1) {
                    return 0;
                }
            } else {
                visited[x[i][j]] = true;
            }
        }
    }
    while(!que.empty()) {
        auto next = que.front();
        if(visited[next]) {
            if(people[next] == 0) {
                return 0;
            }
        }
        que.pop();
        REP(j, x[next].size()) {
            if(y[next][j] == 1) {
                if(!visited[x[next][j]]) {
                    people[x[next][j]] = 1;
                    res++;
                    visited[x[next][j]] = true;
                    que.push(x[next][j]);
                } else {
                    if(people[x[next][j]] == 0) {
                        return 0;
                    };
                }
            } else {
                if(!visited[x[next][j]]) {
                    visited[x[next][j]] = true;
                } else {
                    if(people[x[next][j]] == 1) {
                        return 0;
                    };
                }
            }
        }
    }
    int increment = 0;
    REP(i, N) {
        if(visited[i] == false) {
            increment = max(increment, howmany(i, people, visited));
        }
    }
    return res + increment;
}

int main() {
    cin >> N;
    x.resize(N);
    y.resize(N);
    A.resize(N);
    ll flag = true;
    REP(i, N) {
        int a;
        cin >> a;
        if(a > 0) {
            flag = false;
        }
        A[i] = a;
        REP(j, a) {
            int b, c;
            cin >> b >> c;
            b--;
            c;
            x[i].push_back(b);
            y[i].push_back(c);
        }
    }
    if(flag) {
        cout << N << endl;
        return 0;
    }
    int ans = 0;
    REP(i, N) {
        vector<int> people(N, 0);
        vector<bool> visited(N, false);
        int res = howmany(i, people, visited);
        ans = max(ans, res);
        // cout << res << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256