program Switches
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m,i,j,j2,c,ans,k
    integer(int32), allocatable::p(:)
    logical,allocatable:: s(:,:)
    logical:: all_tuiteru


    read*, n,m
    allocate(s(n,m),source=.false.)
    allocate(p(m))

    block;integer(int32):: inpt(n)
        do i=1,m
            read*, k,inpt(1:k)
            do j=1,k
                s(inpt(j),i) = .true.
            end do
        end do
    end block
    read*, p(:)
    ans=0
    block;logical:: switch(n)
        do i=1,2**n-1
            do j=1,n
                switch(j) = btest(i,j-1)
            end do
            all_tuiteru = .true.
            do j=1,m
                c=0
                do j2=1,n
                    if (s(j2,j) .and. switch(j2)) c=c+1
                end do
                if (mod(c,2) /= p(j)) all_tuiteru = .false.
            end do
            if (all_tuiteru) ans=ans+1
        end do
    end block

    print'(i0)', ans
end program Switches