let ans, n = ref 0, read_int ()
let qs = Array.(init n @@ fun _ -> Scanf.(scanf " %d" @@ fun a -> init a @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b))
let f n = let c, b = ref 0, ref true in for i = 0 to n - 1 do if (n lsr i) land 1 = 1 then (incr c; b := !b && Array.fold_left (fun b (x, y) -> b && (n lsr x) land 1 = y) !b qs.(i)) done; if !b then !c else 0
let _ = for i = 0 to 1 lsl n - 1 do ans := max !ans @@ f i done; Printf.printf "%d\n" !ans