program Switches
    implicit none
    integer(4):: n,m
    integer(4):: i,cnt
    integer(4),allocatable:: k(:), s(:,:),p(:)

    read*, n,m
    allocate(k(m), s(n,n), p(m))
    do i=1,m
        read*, k(i), s(1:k(i),i)
    end do
    read*, p(:)

    cnt = 0
    do i=0,2**(n)-1
        if (all_light(i)) cnt=cnt+1
    end do
    print*, cnt

contains
function all_light(num) result(ret)
    integer(4):: num
    integer(4):: i
    logical:: ret
    
    ret = .true.
    do i=1,m
        if (.not. lon(s(1:k(i),i),num,p(i))) ret = .false.
    end do
end function

function lon(ar,num,p) result(ret)
    integer(4):: ar(:),num,p
    integer(4):: i,cnt=0
    logical:: ret

    cnt=0
    do i=1,size(ar)
        if (mod(rshift(num,ar(i)-1),2) == 1) cnt=cnt+1
    end do
    ret = .false.
    if (mod(cnt,2) == p) ret = .true.
end function
end program Switches