program main
implicit None
	integer(8)::n,m,i,x,p,q,c
	integer(8),allocatable::a(:,:)
	character(len = 100)::s
	
	read*,n,m
	allocate(a(n,m))
	a = 0
	
	do i = 1,n
		read"(a)",s
		x = len_trim(s)
		p = 1
		do while(s(p:p) /= " ")
			p = p+1
		enddo
		
		p = p+1
		q = p
		
		do
			q = p
			if(p /= x)then
				if(s(p+1:p+1) /= " ") q = q+1
			endif
			read(s(p:q),*) c
			a(i,c) = 1
			
			if(p == x .or.q == x) exit
			p = q+2
		enddo
	enddo
	
	p = 0
	do i =1,m
	x = sum(a(:,i))
	if(x ==n) p = p+1
	enddo
	
	print "(i0)",p
end program main