'use strict';
console.log(function(args){
  const _tmp = args.trim().split('\n');
  const N = _tmp.shift()|0;
  const A = [], x = [], y = [];
  for ( let i = 0; i < N; i++ ) {
    A[i] = _tmp.shift()|0;
    x[i] = []; y[i] = [];
    for ( let j = 0; j < A[i]; j++ ) {
      const xy = _tmp[j].split(' ');
      x[i][j] = xy[0]-1; y[i][j] = xy[1]|0;
    }
    _tmp.splice(0,A[i]);
  }
  let K = 0;
  TEST: for ( let honest = 1; honest < 1<<N; honest++ ) {
    let k = 0;
    for ( let i = 0; i < N; i++ ) {
        if ( !(honest&1<<i) ) continue;
      k++;
      for ( let j = 0; j < A[i]; j++ ) {
        const Xij = x[i][j], Yij = y[i][j];
        const target = honest&(1<<Xij);
        if ( target!==(Yij<<Xij) ) continue TEST;
      }
    }
    if ( k > K ) K = k;
  }
  return K;
}(require('fs').readFileSync('/dev/stdin', 'utf8')));
