(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n, m = Scanf.sscanf (read_line ()) "%d %d" ( fun n m -> n, m)

let lst = List.init n ( fun _ -> 
        List.tl (Str.split (Str.regexp " ") (read_line ()))
        |> List.map int_of_string 
        |> Set.of_list
)

let () =
        Set.cardinal (List.fold_left (fun a b -> Set.intersect a b) (List.hd lst) (List.tl lst)) 
        |> Printf.printf "%d\n"
