PROGRAM ATCODER

implicit none
integer :: n,m,i,j,k
integer,allocatable :: count(:)
integer :: a(30,30),a1(30),ans

a = 0
a1 = 0

read(*,*) n,m
allocate(count(m))
count = 0

do i = 1, n
	read(*,*) a1(i), (a(i,j), j=1,a1(i))
end do

do i = 1, m
	do j = 1, 30
    	do k = 1, 30
			if(a(j,k) == i)then
    			count(i) = count(i) +1
   			end if
		end do
	end do
end do

ans = 0
do i = 1, m
	if(count(i) == n)then
    	ans = ans + 1
    end if
end do

write(*,'(i0)') ans

END PROGRAM ATCODER