n, m = list(map(int, input().split()))

denq = []

for _ in range(m):

    ks = tuple([int(x)-1 for x in input().split()])

    denq.append(set(ks[1:]))

P = tuple(map(int, input().split()))



ans = 0

for i in range(2**n):

    kk = [0] * m

    for j in range(n):

        # スイッチjがonの場合

        if (i>>j)&1:

            for idq, dq in enumerate(denq):

                # すべての電球に対して

                # スイッチjが電球に紐付けられていれば、onをカウント

                if j in dq:

                    kk[idq] += 1



    for idq in range(m):

        if P[idq] != kk[idq]%2:

            break

    else:

        ans += 1

print(ans)

n, m = list(map(int, input().split()))

denq = []

for _ in range(m):

    ks = tuple([int(x)-1 for x in input().split()])

    denq.append(ks[1:])

P = tuple(map(int, input().split()))



ans = 0

for i in range(2**n):

    kk = [0] * m

    switch_states = [(i>>j)&1 for j in range(n)]

    for idq, dq in enumerate(denq):

        counts = 0

        for s in dq:

            counts += switch_states[s]

        if counts%2 != P[idq]:

            break

    else:

        ans += 1

print(ans)

n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x) - 1 for x in input().split()])
    denq.append(set(ks[1:]))
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**n):
    kk = [0] * m
    for j in range(n):
        # スイッチjがonの場合
        if (i >> j) & 1:
            for idq, dq in enumerate(denq):
                # すべての電球に対して
                # スイッチjが電球に紐付けられていれば、onをカウント
                if j in dq:
                    kk[idq] += 1
    for idq in range(m):
        if P[idq] != kk[idq] % 2:
            break
    else:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
denq = []
for _ in range(m):
    ks = tuple([int(x) - 1 for x in input().split()])
    denq.append(ks[1:])
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**n):
    kk = [0] * m
    switch_states = [(i >> j) & 1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += switch_states[s]
        if counts % 2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

-    denq.append(set(ks[1:])) +    denq.append(ks[1:]) -    for j in range(n): -        # スイッチjがonの場合 -        if (i >> j) & 1: -            for idq, dq in enumerate(denq): -                # すべての電球に対して -                # スイッチjが電球に紐付けられていれば、onをカウント -                if j in dq: -                    kk[idq] += 1 -    for idq in range(m): -        if P[idq] != kk[idq] % 2: +    switch_states = [(i >> j) & 1 for j in range(n)] +    for idq, dq in enumerate(denq): +        counts = 0 +        for s in dq: +            counts += switch_states[s] +        if counts % 2 != P[idq]: