program main
  implicit none
  integer :: N,M
  integer,allocatable :: K(:)
  type a
     integer,allocatable :: in(:)
  end type a
  integer,allocatable :: Aall(:,:)
  type(a),allocatable :: Ain(:)
  logical :: flag
  integer :: out
  integer :: i,j
  read(*,*) N,M
  allocate(K(N))
  allocate(Ain(N))
  allocate(Aall(N,M))
  do i = 1,N
     read(*,*) K(i),Aall(i,1:K(i))
  end do
  do i = 1,N
     allocate(Ain(i)%in(K(i)))
     Ain(i)%in(:) = Aall(i,1:K(i))
  end do
!  do i = 1,N
!     write(*,*) Ain(i)%in(:)
!  end do
  out=0
  do j = 1,M
     flag=.true.
     do i = 1,N
        if ( any( Ain(i)%in(:) == j ) ) then
           continue
        else
           flag=.false.
        end if
     end do
     if ( flag ) out=out+1
  end do
  write(*,'(i0)') out
  deallocate(Aall)
  
  stop
end program main
