inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
n = inp.shift() * 1
arr = []
max = 0
c = 0
for(i=0;i<n;i++) {
    a = inp.shift() * 1
    arr[i] = new Array(n)
    for(j=0;j<a;j++) {
        l = inp.shift().split(' ')
        x = l[0] - 1
        y = l[1] * 1
        arr[i][x] = y
    }
}

b = []
for(x=Math.pow(2,n)-1;x>=0;x--) {
    ax = new Array(n)
    y = x
    i = 0
    while(y) {
        ax[i] = y % 2
        y >>= 1
        i++
    }
 
    f = 0
    for(i=0;i<n;i++) {
        if (ax[i] != 1) {
            continue;
        } 
        for(j=0;j<n;j++) {
            if (i == j) {
                continue;
            }
            if (arr[i][j] !== undefined) {
                if (ax[j] != arr[i][j]) {
                    f = 1
                    break;
                } 
            }
        }
        if (f) {
            break;
        }
    }
    if (!f) {
        c = ax.filter(x => x == 1).length
        if (max < c) {
            max = c
        }
    }
}
console.log(max)