program main
Implicit None
	integer(8)::n,m,i,j,g,f,e
	integer(8),allocatable::k(:),s(:,:),p(:),gs(:)
	character(len = 60),allocatable::str(:)
	
	read*,n,m
	allocate(k(m),p(m),s(m,n),str(m),gs(n))
	s = 0
	
	do i = 1,m
		read"(a60)",str(i)
	enddo
	read*,p
	
	do i =1,m
		g = 0
		do j = 1,60
			if(str(i)(j:j) == " " .and. g == 0)then
				read(str(i)(1:j-1),*) k(i)
				f = j+1
				g = 1
				cycle
			endif
			if(str(i)(j:j) == " " .and. g /= 0)then
				read(str(i)(f:j-1),*) s(i,g)
				f = j+1
				g = g+1
				if(g > k(i)) exit
			endif
		enddo
	enddo
	
	g = 0
	do i = 0,2**(n)-1
		call nb(i,n,gs)
		do j = 1,m
			e = 0
			do f = 1,n
				if(s(j,f) == 0) exit
				if(gs(s(j,f)) == 1) e = e+1
			enddo
			if (mod(e,2) /= p(j)) exit
			if(j == m) g = g+1
		enddo
	enddo
	print"(i0)",g
end program main

subroutine nb(i1,n,gs)
Implicit None
	integer(8)::i1,i,n,k,p,j
	integer(8)::gs(n)
	
	i = i1
	gs = 0
	k = int(log(real(i))/log(real(2)))+1
	do j = 1,k
		p = mod(i,2)
		i = (i-p)/2
		gs(j) = p
	enddo
end subroutine nb
