open System

let [|N; M|] = stdin.ReadLine().Split(' ') |> Array.map int
let KA = [| for i in 1..N -> (stdin.ReadLine().Split(' ') |> Array.map int).[1..] |> Set.ofArray|]

let f a = Array.reduce (fun l h -> Set.intersect l h) a |> Set.count

f KA |> printf "%d"
