let rec pow x n = if n = 1 then x else x * pow x (n - 1)

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.init n @@ fun _ ->
  let l = Scanf.sscanf (read_line ()) "%d" @@ fun l -> l in
  Array.init l @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun x y -> (x - 1, y)

let x = pow 2 n

let rec to_list x = function
  | 0 -> []
  | n -> x mod 2 :: to_list (x / 2) (n - 1)

let f arr = 
  let res = Array.mapi(fun i t ->
    Array.fold_left (fun z (x, y) -> 
      z && (if t = 1 then arr.(x) = y else arr.(x) <> y)
    ) true a.(i)
  ) arr in
  Array.fold_left (&&) true res

let rec loop m i = 
  if i = x then m 
  else begin
    let arr = Array.of_list @@ to_list i n in
    loop (if f arr then max m (Array.fold_left (+) 0 arr) else m) (i + 1)
  end

let () = Printf.printf "%d\n" @@ loop 0 0