#!/bin/bash
':' /*
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro node:5.2-slim \
  /bin/bash -c "node /vo/$(basename $0) < /vo/g.inp"; exit $?
exit 0
*/
"use strict";

let main = (input) => {
    let n = Number.parseInt(input.shift());
    let syougen = [];
    for (let i = 0; i < n; i++) {
        let m = input.shift();
        let t = [];
        for (let j = 0; j < m; j++) {
            let c = input.shift().split(" ");
            t.push({
                "hito": Number.parseInt(c[0]) - 1,
                "tf": c[1] === "1"
            });
        }
        syougen.push(t);
    }


    let lc = [];
    for(let i=0; i<Math.pow(2,n); i++) lc.push(i);

    lc.sort((a,b) => {
        let aa = a.toString(2).match(/1/g);
        let la = aa==null ? 0:aa.length;
        let bb = b.toString(2).match(/1/g);
        let lb = bb==null ? 0:bb.length;
        return lb-la;
    });

    outer: for(let i of lc){
        let invest = []
        for(let j=0; j<n; j++) invest.push((i&Math.pow(2,j))>>j);
        for(let j=0; j<n; j++){
            if(invest[j]){
                for(let s of syougen[j]){
                    if(s.tf && invest[s.hito]==0) {
                        continue outer;
                    } else if(!s.tf && invest[s.hito]==1) {
                        continue outer;
                    }
                }
            }
        }
        let ans = i.toString(2).match(/1/g);
        return ans==null ? 0:ans.length;
    }

    return 0;
}
console.log(main(require('fs').readFileSync('/dev/stdin', 'utf-8').trim().split("\n")));