open System

let NM = stdin.ReadLine().Split(' ');
let N = NM.[0] |> int;
let M = NM.[1] |> int;


let data : int [] = Array.zeroCreate M
for i in 0..N-1 do
  let mutable ct = stdin.ReadLine().Split(' ');
  let mutable c = ct.[0] |> int;
  for j in 1..c do
    let mutable m = ct.[j] |> int;
    data.[m-1] <- data.[m-1]+1;

let mutable count = 0;
for i in 0..M-1 do
  if data.[i] = N then
     count <- count+1;

count |> printfn "%d"