Program ABC118B

integer n,m,i,j,l,count,x,y
integer k(30),a(30,30)

read(*,*) n,m

do i=1,n
read(*,*) k(i),(a(i,j),j=1,k(i))
end do

count=0

do l=1,k(1)
x=2
do i=2,n
 y=1
 do j=1,k(i)
  if (a(1,l)==a(x,y)) then
   x=x+1
   go to 10
  else
   y=y+1
  end if
 end do
 go to 100
10 end do
count=count+1
100 end do

write(*,*) count

stop
end