program switches
  implicit none
  integer :: n, m, k(10) = 0, s(10,10) = 0, p(10) = 0, u, x = 0, i, j, l, t
  read(*,*) n, m
  do i = 1, m
    read(*,*) k(i), s(i,1:k(i))
  end do
  read(*,*) p(1:m)
  u = ibset(0,n)-1
  do i = 0, u
    do j = 1, m
      t = 0
      do l = 1, k(j)
        if (btest(i,s(j,l)-1)) t = 1-t
      end do
      if (p(j) /= t) goto 100
    end do
    x = x+1
  100 end do
  write(*,'(i0)') x
end program switches