#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF:i64 = std::i64::MAX;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;

#[allow(dead_code)]
fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}
#[allow(dead_code)]
fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

use std::hash::Hash;
#[allow(dead_code)]
fn inc<T: Hash+Ord>(map:&mut BTreeMap<T,i64>, key:T) {
    let count = map.entry(key).or_insert(0);
    *count += 1;
}


fn main() {
    let n:usize = read();
    let mut a = vec![];
    let mut p = vec![];
    for _ in 0..n {
        let t:usize = read();
        a.push(t);
        let mut q = vec![];
        for _ in 0..t {
            let r:Vec<usize> = read_vec();
            q.push((r[0]-1,r[1]))
        }
        p.push(q);
    }

    let mut ans = 0;
    for bit in 0..(1 << n) {
        //debug!(bit);
        let mut f = vec![false;n];
        let mut cnt = 0;
        for i in 0..n {
            if bit & (1 << i) > 0 {
                cnt += 1;
                f[i] = true;
            }
        }
        //debug!(cnt);

        let mut is_ok = true;
        for i in 0..n {
            if bit & (1 << i) == 0 { continue; }
            // 正直者の意見を聞く
            for j in 0..p[i].len() {
                let (x,y) = p[i][j];
                //println!("{}: {} -> {}, f[{}] -> {}", i, x, y, x, f[x]);
                if f[x] != if y==1 {true} else {false} {
                    is_ok = false;
                }
            }
        }
        //debug!(is_ok, cnt);
        if is_ok { ans = max(ans, cnt); }
    }

    println!("{}", ans);
}

/*

bit全探索で仮定する
仮定が妥当かどうか判定し、妥当なら正直者の数を求めて、最大値をとる
妥当かどうかは、正直者だけの意見を確認し、それに矛盾が生じるかどうかを見る
正直者が正直者に対して、不親切と言ってるとき、矛盾となる
正直者が不親切な者に対して、正直者と言ってるとき、矛盾

*/


Measured memory_bytes: 4352