program foods_loved_by_everyone
  implicit none
  integer :: n, m, k, a(30), f(30) = 0, i, j
  read(*,*) n, m
  do i = 1, n
    read(*,*) k, a(1:k)
    do j = 1, k
      f(a(j)) = f(a(j))+1
    end do
  end do
  write(*,'(i0)') sum([(1,i=1,m)],mask=f == n)
end program foods_loved_by_everyone