(* O(n * m) *)
let _ =
  Scanf.scanf " %d %d" @@ fun n m ->
    let counts = Array.make m 0 in
    for _ = 1 to n do
      Scanf.scanf " %d" @@ fun k ->
        for _ = 1 to k do
          Scanf.scanf " %d" @@ fun a ->
            counts.(a - 1) <- counts.(a - 1) + 1
        done
    done;
    let f acc c = acc + if c = n then 1 else 0 in
    Array.fold_left f 0 counts |> Printf.printf "%d\n"