program main
implicit none
integer :: i, j, l, p
integer :: n, m
integer , allocatable :: k(:), a(:), b(:)

read(*,*) n, m
allocate( k(n), a(m), b(m) )
a = 1
do i = 1, n
   read(*,*) k(i), b(1:k(i))
   do j = 1, m
      p = 0
      do l = 1, k(i)
         if( b(l) == j ) then
            p = 1
         end if
      end do
      if( p == 0 ) then
         a(j) = 0
      end if
   end do
end do
write(*,'(i0)') sum(a)
   

end program main
