var ObjectValues = (obj) => {
  var list = []
    for(var i in obj) {
      list.push(obj[i])
    }
  return list
}
var ObjectKeys = (obj) => {
  var list = []
    for(var i in obj) {
      list.push(i)
    }
  return list
}
var ObjectCopy = (obj) => {
  var n_obj = {}
  for(var i in obj) {
    n_obj[i] = (obj[i])
  }
  return n_obj
}
function Main(input) {
  var inputs = input.split("\n").filter(v=>v);
  var member_n = +inputs[0]
  var member_say = {}
  var n = 0;
  for (var i = 1; i < inputs.length;i++) {
    if(inputs[i].length == 1){
      n++;
      member_say[n] = []
    } else {
      member_say[n].push(inputs[i])
    }
  }
  var max = 0
  var calc = (maybe_pure,member_say,status,c_max) => {
    status = status || {};
    c_max = c_max || 0;

    status[maybe_pure] = 1
    var new_pures = []
    for (var str of member_say[maybe_pure]) {
      var name = str.split(' ')[0]
      var val = str.split(' ')[1]
      if(status[name] != null && status[name] != val) {
        return 'fail' //探索終了
      }
      if (status[name] == null && val == 1) {
        new_pures.push(name)
      }
      status[name] = val
    }
    //console.log({status,new_pures})
    for (var _name of new_pures) {
      var result = calc(_name,member_say,status,c_max)
      if(result == 'fail') {
        return 'fail'
      }
      status = result
    }
    return status //探索終了
  }
  var update = (i,member_say,status) => {
    status = status || {};
    var result = calc(i,member_say,status);
    if(result != 'fail') {
      max = ObjectValues(result).filter(v=>v==1).length
      var rKey = ObjectKeys(result);
      //console.log({result,max,rKey})
      if(rKey.length < member_n) {
        var less = [ ...ObjectKeys(member_say) ].filter(key=>rKey.indexOf(key) == -1)
        //console.log({less})
        for (var l of less) {
          update(l,member_say,ObjectCopy(status))
        }
      }
    }
  }
  for (var i = 1; i < member_n;i++) {
    update(i,member_say)
  }

  //console.log(JSON.stringify(member_say,null,'  '));
  //console.log({max});
  console.log(max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
