import numpy as np



def test_switch(e_balls, sw, p):

    for i, e_ball in enumerate(e_balls):

        eb = np.asarray(e_ball)

        si = sw[eb - 1]

        

        if p[i] != (np.sum(si == 1) % 2):

            return False

    

    return True



def transform_sw(sw):

    if sw[0] == 0:

        sw[0] = 1

        return sw

    else:

        sw[0] = 0



    for i, s in enumerate(sw[1:]):

        if s == 0:

            sw[i + 1] = 1

            return sw

        elif s == 1:

            sw[i + 1] = 0

    

    return sw





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



e_balls = []



for m in range(M):

    i = input().split()

    s = [int(si) for si in i[1:]]

    e_balls.append(s[:])



p = [int(pi) for pi in input().split()]



sw = np.array([0 for _ in range(N)])

cnt = 0



while np.sum(sw == 1) != N:

    if test_switch(e_balls, sw, p):

        cnt += 1

    transform_sw(sw)



if test_switch(e_balls, sw, p):

        cnt += 1



print(cnt)
import numpy as np

import itertools as ittr



def test_switch(e_balls, sw, p):

    for i, e_ball in enumerate(e_balls):

        eb = np.asarray(e_ball)

        si = sw[eb - 1]

        

        if p[i] != (np.sum(si == 1) % 2):

            return False

    

    return True



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



e_balls = []



for m in range(M):

    i = input().split()

    s = [int(si) for si in i[1:]]

    e_balls.append(s[:])



p = [int(pi) for pi in input().split()]



cnt = 0



for sw in ittr.product([0, 1], repeat = N):

    if test_switch(e_balls, np.array(sw), p):

        cnt += 1



print(cnt)
import numpy as np


def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        if p[i] != (np.sum(si == 1) % 2):
            return False
    return True


def transform_sw(sw):
    if sw[0] == 0:
        sw[0] = 1
        return sw
    else:
        sw[0] = 0
    for i, s in enumerate(sw[1:]):
        if s == 0:
            sw[i + 1] = 1
            return sw
        elif s == 1:
            sw[i + 1] = 0
    return sw


N, M = list(map(int, input().split()))
e_balls = []
for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])
p = [int(pi) for pi in input().split()]
sw = np.array([0 for _ in range(N)])
cnt = 0
while np.sum(sw == 1) != N:
    if test_switch(e_balls, sw, p):
        cnt += 1
    transform_sw(sw)
if test_switch(e_balls, sw, p):
    cnt += 1
print(cnt)

import numpy as np
import itertools as ittr


def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        if p[i] != (np.sum(si == 1) % 2):
            return False
    return True


N, M = list(map(int, input().split()))
e_balls = []
for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])
p = [int(pi) for pi in input().split()]
cnt = 0
for sw in ittr.product([0, 1], repeat=N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1
print(cnt)

+import itertools as ittr -def transform_sw(sw): -    if sw[0] == 0: -        sw[0] = 1 -        return sw -    else: -        sw[0] = 0 -    for i, s in enumerate(sw[1:]): -        if s == 0: -            sw[i + 1] = 1 -            return sw -        elif s == 1: -            sw[i + 1] = 0 -    return sw - - -sw = np.array([0 for _ in range(N)]) -while np.sum(sw == 1) != N: -    if test_switch(e_balls, sw, p): +for sw in ittr.product([0, 1], repeat=N): +    if test_switch(e_balls, np.array(sw), p): -    transform_sw(sw) -if test_switch(e_balls, sw, p): -    cnt += 1