let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_ss = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun k -> Array.init k @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a - 1
let cs = Array.make m 0
let f a_s = Array.iter (fun a -> cs.(a) <- cs.(a) + 1) a_s
let _ = Array.iter f a_ss; Array.fold_left (fun ans c -> ans + if c = n then 1 else 0) 0 cs |> Printf.printf "%d\n"