CodeEff/ECCO huggingface dataset:
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = LIR(m)
    p = LI()
    ans = 0
    for i in range(m):
        s[i] = sum([1<<(j-1) for j in s[i][1:]])
    for b in range(1<<n):
        for i in range(m):
            if bin(s[i]&b).count("1")&1 != p[i]:
                break
        else:ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = []
    for i in range(m):
        a = LI()[1:]
        for j in range(len(a)):
            a[j] -= 1
        s.append(a)
    p = LI()
    ans = 0
    for b in range(1<<n):
        su = [0]*m
        for i in range(m):
            for j in s[i]:
                if b&(1<<j):
                    su[i] ^= 1
        if su == p:
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
N, M = list(map(int, input().split()))
kss = [list(map(int, input().split())) for _ in range(M)]
ps = list(map(int, input().split()))

answer = 0
for i in range(1 << N):
    for (_, *ss), p in zip(kss, ps):
        okay = True
        if sum([(i >> s-1) & 1 for s in ss]) % 2 != p:
            okay = False
            break
    if okay:
        answer += 1

print(answer)


# Optimized solution
from itertools import product

N, M = list(map(int, input().split()))
kss = [list(map(int, input().split())) for _ in range(M)]
ps = list(map(int, input().split()))

answer = 0
for switches in product(list(range(2)), repeat=N):
    for (_, *ss), p in zip(kss, ps):
        okay = True
        if sum([switches[s-1] for s in ss]) % 2 != p:
            okay = False
            break
    if okay:
        answer += 1

print(answer)
# Original solution
N,M=list(map(int,input().split()))
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    flag=True
    for m in range(M):
        on=0
        for n in range(N):
            if (i>>n)&1 and n+1 in s[m]:
                on+=1
        if on%2!=p[m]:
            flag=False
    if flag:
        count+=1
print(count)

# Optimized solution
N,M=list(map(int,input().split()))
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for bit in range(1<<N):
    flag=True
    for m in range(M):
        on=0
        for n in range(N):
            if (bit>>n)&1 and n+1 in s[m]:
                on+=1
        if on%2!=p[m]:
            flag=False
    if flag:
        count+=1
print(count)
# Original solution
n,m = list(map(int,input().split()))
ls = []
switch = [(i+1) for i in range(n)]
ls = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

pattern = [bin(i)[2:].zfill(n) for i in range(2**n)]

ans = 0

for i in pattern:
    turn = []
    on = 0
    for j in range(n):
        if i[j] == '1':
            turn.append(switch[j])
    for k in range(m):
        count = 0
        for l in range(1,ls[k][0]+1):
            if ls[k][l] in turn:
                count += 1
        if count % 2 == p[k]:
            on += 1
    if on == m:
        ans += 1
            
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
switch = [(i+1) for i in range(n)]
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
pattern = [bin(i)[2:].zfill(n) for i in range(2**n)]

ans = 0

for i in pattern:
    on = []
    light = 0
    for j in range(n):
        if i[j] == '1':
            on.append(switch[j])
    for k in range(m):
        count = 0
        for l in range(1,ks[k][0]+1):
            if ks[k][l] in on:
                count += 1
        if count % 2 == p[k]:
            light += 1
    if light == m:
        ans += 1
            
print(ans)
# Original solution
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
for ii in range(2**N):
    check = True
    for i in range(M):
        cnt = 0
        for j in range(1, len(ks[i])):
            if (ii >> (ks[i][j]-1)) & 1:
                cnt += 1
        if cnt % 2 != p[i]:
            check = False
            break
    if check:
        ans += 1
print(ans)

# Optimized solution
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    flag = True
    for j in range(m):
        cnt = 0
        for k in range(1, len(ks[j])):
            if (i >> (ks[j][k]-1)) & 1:
                cnt += 1
        if cnt % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)
# Original solution
import math


def number2bit(n):
    return int(math.pow(2, n - 1))


def count_bit(n):
    count = 0
    while n > 0:
        if n & 1 == 1:
            count += 1
        n >>= 1
    return count


N, M = list(map(int, input().split(' ')))
lights = [set(tuple(map(int, input().split(' ')))[1:]) for _ in range(M)]
light_bits = [sum(map(number2bit, light)) for light in lights]
mods = tuple(map(int, input().split(' ')))

count = 0
for i in range(int(math.pow(2, N))):
    for j, light_bit in enumerate(light_bits):
        if count_bit(i & light_bit) % 2 != mods[j]:
            break
    else:
        count += 1

print(count)


# Optimized solution
import math


def number2bit(n):
    return int(math.pow(2, n - 1))


def count_bit(n):
    return bin(n)[2:].count('1')


N, M = list(map(int, input().split(' ')))
lights = [tuple(map(int, input().split(' ')))[1:] for _ in range(M)]
light_bits = [sum(map(number2bit, light)) for light in lights]
mods = tuple(map(int, input().split(' ')))

count = 0
for i in range(int('1' + '0' * N, base=2)):
    for light_bit, mod in zip(light_bits, mods):
        if count_bit(i & light_bit) % 2 != mod:
            break
    else:
        count += 1

print(count)
# Original solution
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]

S = [[0] * N for _ in range(M)]
for m in range(M):
    s = [int(x) for x in input().split()]
    for s1 in s[1:]:
        S[m][s1 - 1] = 1

P = [int(x) for x in input().split()]

cnt = 0
for i in range(2 ** N):
    tmp = True
    for j in range(M):
        c = 0
        for k in range(N):
            if i & (1 << k):
                c += S[j][k]

        if c % 2 != P[j]:
            tmp = False

        # bit = format(i, "08b")
        # print("i(bit):{}, j:{}, c:{},c%2:{}, P[j]:{}".format(bit, j, c, c % 2, P[j]))
    # print("---")

    if tmp == True:
        cnt += 1

print(cnt)


# Optimized solution
N, M = list(map(int, input().split()))

S = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    k = tmp[0]
    S.append(tmp[1:])
P = [int(x) for x in input().split()]

ret = 0
for pt in range(1<<N):
    allOn = True
    for i in range(M):
        swcnt = 0
        for s in S[i]:
            if pt & (1 << (s-1)):
                swcnt += 1
        if swcnt % 2 != P[i]:
            allOn = False
    if allOn:
        ret += 1

print(ret)
# Original solution
N, M = list(map(int, input().split()))

S = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    k = tmp[0]
    S.append(tmp[1:])
P = [int(x) for x in input().split()]

ret = 0
for pt in range(1<<N):
    allOn = True
    for i in range(M):
        swcnt = 0
        for s in S[i]:
            if pt & (1 << (s-1)):
                swcnt += 1
        if swcnt % 2 != P[i]:
            allOn = False
    if allOn:
        ret += 1

print(ret)


    

# Optimized solution
N, M = list(map(int, input().split()))

S = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    k = tmp[0]
    S.append(tmp[1:])
P = [int(x) for x in input().split()]

ret = 0
# bitでN個のスイッチ押し方の全パターンを列挙する方針
for pt in range(1<<N):
    allOn = True
    # 電球iが点灯するかどうか
    for i in range(M):
        cnt = 0     # 電球iに対応したスイッチの中で押した数 
        for s in S[i]:
            if pt & (1 << (s-1)):
                cnt += 1
        if cnt % 2 != P[i]:
            allOn = False
    if allOn:
        ret += 1

print(ret)
# Original solution
N, M = list(map(int,input().split()))
s = []
ans = 0
for _ in range(M):
    temp = list(map(int, input().split()))
    s.append(temp[1:])
p = list(map(int, input().split()))
for i in range(2 ** N):
    flag = 1
    flag_1 = 1
    sw = bin(i)[2:]
    sw = sw.zfill(N)
    for j in range(M):
        sumsw = 0
        for k in s[j]:
            sumsw += int(sw[k-1])
        if sumsw % 2 != p[j]:
            flag = 0
            flag_1 = 0
            break
        if flag_1 == 0:
            break
    if flag:
        ans += 1
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

N, M = [int(x) for x in input().split()]
k = []
s = []
for _ in range(M):
    tmp = [int(x) for x in input().split()]
    k.append(tmp[0])
    s.append(tmp[1:])
p = [int(x) for x in input().split()]

ans = 0

for i in range(2 ** N):
    flag = 1
    for j in range(M):
        cnt = 0
        for k in s[j]:
            cnt += (i >> (k - 1)) & 1
        if cnt % 2 != p[j]:
            flag = 0
            break
    ans += flag

print(ans)
# Original solution
n,m = list(map(int,input().split()))
s = [0]*m
for i in range(m):
    s[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0

for i in range(2**n):
    sw = [0]*m
    for k in range(m):
        num = 0
        for j in range(n):
            if (i>>j)&1:
                if j+1 in s[k][1:]:
                    num += 1
        if num%2 == p[k]:
            sw[k] = 1
    if 0 in sw:
        pass
    else:
        ans += 1
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
s = [0]*m
for i in range(m):
    s[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    sw = [0]*m
    for j in range(m):
        num = 0
        for k in range(n):
            if (i>>k)&1:
                if k+1 in s[j][1:]:
                    num += 1
        if num%2 == p[j]:
            sw[j] = 1
    if 0 in sw:
        pass
    else:
        ans += 1
print(ans)
# Original solution
import copy

num_of_switch, num_of_lights = [int(_) for _ in input().split()]


def toSwitch(xs):
    xs[1:]


S = [[int(s) - 1 for s in input().split()[1:]] for i in range(num_of_lights)]
P = [_ == "1" for _ in input().split()]

# i は switch の添字


def rec(switch_idx, lights):
    if switch_idx == num_of_switch:
        if lights == P:
            return 1
        else:
            return 0

    switch_off_result = rec(switch_idx + 1, lights)

    _lights = copy.deepcopy(lights)

    for light_idx in range(num_of_lights):
        # print(f"switch_idx = {switch_idx}, light_idx = {light_idx}")
        is_connect = switch_idx in S[light_idx]
        if is_connect:
            _lights[light_idx] = not _lights[light_idx]

    # print(f"switch_idx = {switch_idx}: not choose = {lights}, choose = {_lights} ")

    switch_on_result = rec(switch_idx + 1, _lights)

    return switch_off_result + switch_on_result


ans = rec(0, [False] * num_of_lights)
print(ans)


# Optimized solution
import copy

num_of_switch, num_of_lights = [int(_) for _ in input().split()]

S = [[int(s) - 1 for s in input().split()[1:]] for i in range(num_of_lights)]
P = [_ == "1" for _ in input().split()]

# i は switch の添字


def rec(switch_idx, lights):
    if switch_idx == num_of_switch:
        if lights == P:
            return 1
        else:
            return 0

    switch_off_result = rec(switch_idx + 1, lights)

    _lights = copy.deepcopy(lights)

    for light_idx in range(num_of_lights):
        # print(f"switch_idx = {switch_idx}, light_idx = {light_idx}")
        is_connect = switch_idx in S[light_idx]
        if is_connect:
            _lights[light_idx] = not _lights[light_idx]

    # print(f"switch_idx = {switch_idx}: not choose = {lights}, choose = {_lights} ")

    switch_on_result = rec(switch_idx + 1, _lights)

    return switch_off_result + switch_on_result


ans = rec(0, [False] * num_of_lights)
print(ans)
# Original solution
N,M=list(map(int,input().split()))
L=[list(map(int,input().split())) for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch[1:]:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=True
    else:
      lit[j]=False
  if all(lit):
    ans+=1
print(ans)

# Optimized solution
N,M=list(map(int,input().split()))
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=True
    else:
      lit[j]=False
  if all(lit): ans+=1 
print(ans)
# Original solution
N,M=list(map(int,input().split()))
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switch in enumerate(L):
    cnt=0
    for s in switch:
      if i>>(s-1)&1:
        cnt+=1
    if cnt%2==P[j]:
      lit[j]=1
    else:
      lit[j]=0
  if all(lit): ans+=1 
print(ans)

# Optimized solution
N,M=list(map(int,input().split()))
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  lit=[0]*M
  for j,switches in enumerate(L):
    cnt=0
    for s in switches:
      if i>>(s-1)&1:cnt+=1
    if cnt%2==P[j]:lit[j]=1
  if all(lit):ans+=1 
print(ans)
# Original solution
N,M = list(map(int, input().split()))
S = []
for _ in range(M):
  s_list = ['0' for _ in range(N)]
  for s in list(map(int, input().split()))[1:]:s_list[s-1] = '1'
  S.append(int(''.join(s_list),2))

P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
  flag = True
  for idx, s in enumerate(S):
    if bin(i&s)[2:].count('1')%2 != P[idx]:
      flag = False
      break
  if flag is True: ans += 1
print(ans)

# Optimized solution
def is_all_switches_on(on_case):
    for i, s in enumerate(S):
        on_switch_num = 0
        for si in s:
            if on_case[si] == '1':
                on_switch_num += 1

        if on_switch_num % 2 != switches[i]:
            return False
    return True

if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    S = []
    for _ in range(M):
        k, *s = list(map(int, input().split()))
        S.append(s)

    switches = list(map(int, input().split()))

    ans = 0
    for i in range(2 ** N):

        on_case = '0' + bin(i)[2:].zfill(N)
        if is_all_switches_on(on_case):
            ans += 1
    print(ans)
# Original solution
n,m = list(map(int,input().split()))
k = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
ans = 0
switch_st = 0
cnt = 0

while switch_st != 2**n:
    switch_on = { i+1 for i in range(n) if switch_st>>i & 1 == 1}
    for i in range(m):
        switch_cnt = len(switch_on & set(k[i][1:]))
        if switch_cnt %2 == p[i]:
            cnt += 1
    else:
        if cnt == m:
            ans += 1
    cnt = 0
    switch_st += 1

print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
S = [[int(i)-1 for i in input().split()] for _ in range(M)]
P = [int(i) for i in input().split()]

ans = 0
for i in range(1<<N):
    for j in range(M):
        cnt = 0
        for s in S[j][1:]:
            if i >> s & 1: cnt += 1
        if cnt%2 != P[j]: break
    else:
        ans += 1

print(ans)
# Original solution
N,M = list(map(int,input().split()))
#ks[i][0]がk_i
ks = [[int(i) for i in input().split()]for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
    flag=0
    #Onoff[i]=0はスイッチiのOFFを、=1はONを表す
    OnOff = [0]*N
    for j in range(N):
        if (i>>j) & 1:
            OnOff[j]=1
    
    for j in range(M):
        count=0
        for l in range(1,len(ks[j])):
            if(OnOff[ks[j][l]-1]==1):
                count+=1
        if(p[j]==0 and count%2==0):
            flag+=1
        elif(p[j]==1 and count%2==1):
            flag+=1
        else:
            pass
    
    if(flag==len(p)):
        ans+=1
print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
#ks[i][0]がk_i
ks = [[int(i) for i in input().split()]for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
    flag=0
    #Onoff[i]=0はスイッチiのOFFを、=1はONを表す
    OnOff = [0]*N
    for j in range(N):
        if (i>>j) & 1:
            OnOff[j]=1
    
    for j in range(M):
        count=0
        for l in range(1,len(ks[j])):
            if(OnOff[ks[j][l]-1]==1):#-1に注意（スイッチxはOnOff[x-1]に対応）
                count+=1
        if(p[j]==0 and count%2==0):
            flag+=1
        elif(p[j]==1 and count%2==1):
            flag+=1
        else:
            pass
    #全ての電球が点くならばansに+1
    if(flag==len(p)):
        ans+=1
print(ans)
# Original solution
N,M = [int(i) for i in input().split()] #Nがスイッチの数、Mは電球の数
kslist = []
for i in range(M):
    kslist.append([int(i)-1 for i in input().split()][1:])
plist = [int(i) for i in input().split()]

#print(kslist)
#print(plist)

count = 0

lamp_str = "0"*N
for i in range(2**N):
    lamp_onoff_list = [int(i) for i in lamp_str]
    iflampturnson = [0 for i in range(M)]
    for j in range(M):
        for s in kslist[j]:
            iflampturnson[j] += lamp_onoff_list[s]
    #print(lamp_onoff_list,iflampturnson)
    iflampturnson = [k%2 for k in iflampturnson]
    
    buff = True
    for k in range(M):
        if plist[k] != iflampturnson[k]:
            buff = False
    if buff == True:
        count += 1

    lamp_str = format(int(lamp_str,2) + 1,"b")
    lamp_str = lamp_str.zfill(N)

print(count)



# Optimized solution
N,M = [int(i) for i in input().split()]
switches = []
for i in range(M):
    buff = 0
    k,*sss = [int(i) for i in input().split()]
    for s in sss:
        buff += 1 << (s-1)
    switches.append(buff)

ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1<<N):
    for p,s in zip(ppp,switches):
        buff = s&i
        buff = bin(buff).count("1")%2
        if buff != p:
            break
    else:
        ans += 1

print(ans)
# Original solution
N,M = [int(i) for i in input().split()] #Nがスイッチの数、Mは電球の数
sss = []
for i in range(M):
    buff = [int(i)-1 for i in input().split()][1:]
    onoff = [0 for i in range(N)]
    for j in buff:
        onoff[j]=1
    sss.append(onoff)

ppp = [int(i) for i in input().split()]

ct=0
for i in range(1<<N):
    bitcode = [int(i) for i in list(bin(i)[2:].zfill(N))]
    for s,p in zip(sss,ppp):
        if sum(j*k for j,k in zip(s,bitcode))%2!=p:
            break
    else:
        ct+=1

print(ct)

# Optimized solution
N,M = [int(i) for i in input().split()]
switches = []
for i in range(M):
    buff = 0
    k,*sss = [int(i) for i in input().split()]
    for s in sss:
        buff += 1 << (s-1)
    switches.append(buff)

ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1<<N):
    for p,s in zip(ppp,switches):
        buff = s&i
        buff = bin(buff).count("1")%2
        if buff != p:
            break
    else:
        ans += 1

print(ans)
# Original solution
# -*- coding:utf-8 -*-
from itertools import combinations
import copy

def solve2():
    """
    itertools.productを使えばもっとすっきり？
    """
    import itertools as it
    N, M = list(map(int, input().split()))
    K = []
    S = []
    for i in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    switch_stats = it.product((0,1), repeat=N)

    ans = 0
    for stats in switch_stats:
        is_ok = True
        for i in range(M):  # すべての電球において
            on_num = 0
            for s_i in S[i]:
                on_num += 1 if stats[s_i-1]==1 else 0
            if on_num%2 == P[i]:
                continue
            else:
                is_ok = False
        
        if is_ok:
            ans += 1
    
    print(ans)


def solve():
    N, M = list(map(int, input().split()))
    K = []
    S = []
    for i in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    """
    全探索
    計算量 O(2^N * M * max(len(S)))
    N=10, M=10でも、1024 * 10 * 10 くらい？
    """
    def dfs(switch_stats):
        if len(switch_stats)==N:
            is_ok = True
            for i in range(M):
                on_num = 0
                for switch_i in S[i]:
                    on_num += 1 if switch_stats[switch_i-1] == 1 else 0
                if on_num%2 == P[i]:
                    continue
                else:
                    is_ok = False
                    break
            
            if is_ok:
                return 1
            else:
                return 0
        switch_stats1 = copy.deepcopy(switch_stats)
        switch_stats1.append(0)
        ret1 = dfs(switch_stats1)
        switch_stats2 = copy.deepcopy(switch_stats)
        switch_stats2.append(1)
        ret2 = dfs(switch_stats2)
        return ret1 + ret2

    ans = dfs([])
    print(ans)


if __name__ == "__main__":
    solve2()


# Optimized solution
# -*- coding:utf-8 -*-
from itertools import product

def solve():
    N, M = list(map(int, input().split()))
    K, S = [], []
    for _ in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    all_stats = product((0,1), repeat=N)
    ans = 0
    for stat in all_stats:
        is_ok = True
        for switch_i, switch in enumerate(S):
            on_num = 0
            for i in range(len(switch)):
                if stat[switch[i]-1] == 1:
                    on_num += 1
            if on_num%2 != P[switch_i]:
                is_ok = False
                break
        if is_ok:
            ans += 1
    print(ans)

if __name__ == "__main__":
    solve()