module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d" @@ fun n m ->
  let set_ary = Array.init n @@ fun _ ->
    Scanf.scanf " %d" @@ fun k -> 
      let ary = Array.init k @@ fun _ -> Scanf.scanf " %d" Fun.id in
      IntSet.of_list @@ Array.to_list ary in
  Printf.printf "%d\n" @@ IntSet.cardinal @@ Array.fold_left IntSet.inter set_ary.(0) set_ary