program main
  implicit none
  integer :: n, m, k, a(30), i, j
  logical, allocatable :: flag(:, :)
  read (*, *) n, m
  allocate (flag(n, m))
  flag(:, :) = .false.
  do i = 1, n
    read (*, *) k, (a(j), j = 1, k)
    do j = 1, k
      flag(i, a(j)) = .true.
    end do
  end do
  print "(i0)", count(all(flag(:, :), dim=1))
end program main
