let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)


let () = Scanf.scanf "%d\n" @@ fun n ->
  let xyss =
    Array.init n @@ fun _ ->
      Scanf.scanf "%d\n" @@ fun a ->
        Array.to_list @@ Array.init a @@ fun _ ->
          Scanf.scanf "%d %d\n" @@ fun x y -> x, y in
  Printf.printf "%d\n" @@
  Array.fold_left max min_int @@
  Array.init (1 lsl n) @@ fun ans ->
    if
      Array.fold_left ( && ) true @@
      Array.init n @@ fun i ->
        if ans land (1 lsl i) = 0
        then true
        else
          List.for_all (fun (x, y) ->
            ans land (1 lsl (x - 1)) = y lsl (x - 1)) xyss.(i)
    then popcnt ans
    else 0

