function main(input) {
  const inputs = input.split('\n');
  var n = inputs[0] - 0;

  var a = 0;
  var aLine = 1;
  var people = [];
  for (var i = 0; i < n; i++) {
    var a = inputs[aLine] - 0;
    people.push([]);
    var temp = [];
    for (var j = 1; j <= a; j++) {
      temp.push(inputs[aLine + j].split(' ').map((n) => n - 0));
    }
    people[i] = temp;
    aLine += a + 1;
  }

  var initTemp = [];
  for (var i = 0; i < n; i++) {
    initTemp.push(0);
  }

  var temp = initTemp.concat();
  var max = -1;
  for (var bit = 0; bit < (1 << n); bit++) {
    var counter = 0;
    var isOK = true;
    for (var bi = 0; bi < n; bi++) {
      temp[bi] = bit & (1 << bi) ? 1 : 0;
    }
    for (var bi = 0; bi < n; bi++) {
      if (!(bit & (1 << bi))) {
        if (temp[bi] == 1) isOK = false;
      } else {
        counter += 1;
        if (temp[bi] == 0) {
          isOK = false;
          break;
        }
        for (var pi = 0; pi < people[bi].length; pi++) {
          if (temp[people[bi][pi][0] - 1] != people[bi][pi][1]) {
            isOK = false;
            break;
          }
        }
      }
    }
    if (isOK) max = Math.max(max, counter);
  }
  console.log(max);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
