program atcoder
    implicit none
    integer(8) :: i,j,n,m,ans=0,k
    integer(8),allocatable,dimension(:) :: a,sum
    read*,n,m
    allocate(a(m))
    allocate(sum(m))
    sum = 0
    do i=1,n
        a = 0
        read(*,*)k,(a(j),j=1,k)
        do j=1,k
            sum(a(j)) = sum(a(j)) + 1
        enddo
    enddo
    do i=1,m
        if(sum(i)==n)then
            ans = ans + 1
        endif        
    enddo
    write(*,'(i0)')ans
    stop 
contains
end program atcoder