function main(input) {
  var N = input[0]-0;
  var list = [];
  var idx = 0;
  for(var i=0;i<N;i++){
    var a = input[++idx]-0;
    var alist = [];
    list.push(alist);
    for(var j=0;j<a;j++){
      var obj = input[++idx].split(" ").map(v=>v-0);
      --obj[0];
      alist.push(obj);
    }
  }

  var ans = 0;
  for(var i=1;i<Math.pow(2,N);i++){
    ans = Math.max(ans, calc(list, i));
  }
  console.log(ans);

}

function calc(list, pt){
  var ptn = ("0000000000000000" + pt.toString(2)).slice(-1*list.length);
  for(var i=0;i<list.length;i++){
    var data = list[i];
    if(ptn[i]=="1") for(var j=0;j<data.length;j++){
      var d = data[j];
      if(d[1]=="1" && ptn[d[0]] != "1") return 0;
      else if(d[1]=="0" && ptn[d[0]] != "0") return 0;
    }
  }
  return ptn.replace(/0/g,"").length;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
