Imports System.Collections.Generic
Public Class Program
  Shared Sub Main()
    Dim nm() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim n As Integer = nm(0)
    Dim m As Integer = nm(1)
    Dim all As Integer() = Nothing
    For i As Integer = 0 To n - 1
      Dim ka() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
      Dim k As Integer = ka(0)
      Dim a(0 To k - 1) As Integer
      Array.Copy(ka, 1, a, 0, k)
      If i = 0 Then
        all = a
      Else
        all = Array.FindAll(Of Integer)(all, AddressOf DirectCast(a, IList(Of Integer)).Contains)
      End If
    Next
    Console.WriteLine(all.Length())
  End Sub
End Class