'use strict';
const main = input => {
  const n = parseInt(input[0]);
  let a = [];
  let a_ = 1;
  let arr = new Array(n);
  for(let i=0; i<n; i++) {
    a[i] = parseInt(input[a_]);
    arr[i] = new Array(a[i]).fill({x:0,y:0});
    for(let j=0; j<a[i]; j++) {
      let p = input[a_+j+1].split(' ').map(val => parseInt(val));
      arr[i][j] = {x: p[0]-1, y: p[1]};
    }
    a_ += a[i]+1;
  }
  // console.log(a, arr);
  const toBinary = (s,n) => {
    let t = s.toString(2);
    while(t.length < n) {
      t = '0'+ t;
    }
    return t;
  }

  for(let i=Math.pow(2,n)-1; i>=0; i--) {
    let z = toBinary(i,n);
    let check = true;
    for(let j=0; j<n; j++) {
      arr[j].map(val => {
        if (z[j] == 1 && z[val.x] != val.y) {
          check = false;
        }
      })
    }
    if (check) {
      let ans = z.split('').filter(word => word == '1').length;
      // console.log(`^^^^^^${ans}`);
      // console.log(`${z}^^^^^^^^`);
      return console.log(ans)
    }
  }
  return console.log(0);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));