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)



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)
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)

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)

-N, M = [int(i) for i in input().split()]  # Nがスイッチの数、Mは電球の数 -kslist = [] +N, M = [int(i) for i in input().split()] +switches = [] -    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) +    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)