let rec check2 lst n = List.for_all (fun l -> List.mem n l) lst
let rec check lst n =
  if n = 0 then 0
  else if check2 lst n then 1 + check lst (n-1)
  else check lst (n-1)
let () =
  let (n, m) = Scanf.scanf "%d %d\n" (fun x y -> (x, y)) in
  let lst = Array.to_list (Array.init n (fun _ -> Scanf.scanf "%d " (fun k -> Array.to_list (Array.init k (fun _ -> Scanf.scanf "%d " (fun x -> x)))))) in
  Printf.printf "%d\n" (check lst m)