program ABC118B
    implicit none
    integer(8)::h,i,j
    integer(8)::N,M,K
    integer(8)::result=0
    integer(8),allocatable,dimension(:)::S,A

    read(5,*)N,M
    allocate(S(M))
    allocate(A(M))

    do i=1,M
        S(i)=0
    end do

    do h=1,N
        read(5,*)K,(A(i),i=1,K)

        do j=1,K
            S(A(j))=S(A(j))+1
        end do
    end do

    do i=1,M
        if(S(i)==N)then
            result=result+1
        end if
    end do

    print'(i0)',result
    
end program ABC118B