let _ =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let aa = Array.make n [] in
  for i = 0 to n - 1 do
    let k = Scanf.scanf "%d " (fun k -> k) in
    for j = 1 to k do
      Scanf.scanf (if j <> k then "%d " else "%d\n") 
        (fun a -> aa.(i) <- a::aa.(i)) 
    done
  done;
  let reslist = ref aa.(0) in
  for i = 1 to n - 1 do
    reslist := List.filter (fun e -> List.mem e aa.(i)) !reslist
  done;
  List.length !reslist
  |> print_int