program bbb
implicit none

integer :: n,m,i,j,res
integer,dimension(30) :: a, b
integer,allocatable, dimension(:) :: k

read*, n,m
allocate(k(n))

res=0
b=0

do i=1,n
a=0
read*, k(i), a(1:k(i))
 do j=1,k(i)
 b(a(j))=b(a(j))+1
 end do
end do

do i=1,m
if(b(i)==n) res=res+1
end do
write(*,'(i0)') res

end program