program main
implicit none
integer :: n, m
integer , allocatable :: k(:), A(:,:), Ai(:)
integer :: i, j, l, nc

read(*,*) n, m
allocate(k(n))
allocate(A(n,m))
do i = 1, n
   read(*,*) k(i)
   allocate(Ai(k(i)))
   read(*,*) Ai(:)
   do j = 1, k(i)
      do l = 1, m
         if(l == ai(j)) then
            a(i,l) = 1
         else
            a(i,l) = 0
         end if
      end do
   end do
   deallocate(Ai)
end do

nc = 0
do j = 1, m
   if(sum(a(:,j)) = m ) then
      nc = nc + 1
   end if
end do
write(*,'(i0)') nc
deallocate(k)
deallocate(a)
stop
end program main
