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

S = []

for _ in range(M):

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

    S.append([True if i in ipt[1:] else False for i in range(1, N+1)])

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



ans = 0

for cmb in range(0, 2**N):

    b = list(str(bin(cmb)))[2:]

    cmb_b = ["0"]*(N-len(b)) + b

    cur_cnd = [0]*M

    for s_cnd, i in zip(reversed(cmb_b), list(range(N))):

        for s, j in zip(S, list(range(M))):

            if s_cnd == "1" and s[i]:

                cur_cnd[j] = (cur_cnd[j]+1) % 2

    if P == cur_cnd:

        ans += 1



print(ans)
import sys





input = sys.stdin.readline





def make_switch_set(i, s):

    if i == N:

        return [s]

    else:

        cs = s.copy()

        cs.add(i+1)

        return make_switch_set(i+1, s) + make_switch_set(i+1, cs)





def main():

    ans = 0

    for ss in switch_set:

        count = 0

        for switches, p in zip(S, P):

            match_num = len(ss & switches)

            if match_num % 2 == p:

                count += 1

        if count == M:

            ans += 1

    print(ans)





if __name__ == "__main__":

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

    S = []

    for _ in range(M):

        ipts = [int(ipt) for ipt in input().split()]

        S.append(set(ipts[1:]))

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

    switch_set = make_switch_set(0, set())

    main()
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    ipt = [int(i) for i in input().split()]
    S.append([True if i in ipt[1:] else False for i in range(1, N + 1)])
P = [int(p) for p in input().split()]
ans = 0
for cmb in range(0, 2**N):
    b = list(str(bin(cmb)))[2:]
    cmb_b = ["0"] * (N - len(b)) + b
    cur_cnd = [0] * M
    for s_cnd, i in zip(reversed(cmb_b), list(range(N))):
        for s, j in zip(S, list(range(M))):
            if s_cnd == "1" and s[i]:
                cur_cnd[j] = (cur_cnd[j] + 1) % 2
    if P == cur_cnd:
        ans += 1
print(ans)

import sys

input = sys.stdin.readline


def make_switch_set(i, s):
    if i == N:
        return [s]
    else:
        cs = s.copy()
        cs.add(i + 1)
        return make_switch_set(i + 1, s) + make_switch_set(i + 1, cs)


def main():
    ans = 0
    for ss in switch_set:
        count = 0
        for switches, p in zip(S, P):
            match_num = len(ss & switches)
            if match_num % 2 == p:
                count += 1
        if count == M:
            ans += 1
    print(ans)


if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    S = []
    for _ in range(M):
        ipts = [int(ipt) for ipt in input().split()]
        S.append(set(ipts[1:]))
    P = [int(p) for p in input().split()]
    switch_set = make_switch_set(0, set())
    main()

-N, M = list(map(int, input().split())) -S = [] -for _ in range(M): -    ipt = [int(i) for i in input().split()] -    S.append([True if i in ipt[1:] else False for i in range(1, N + 1)]) -P = [int(p) for p in input().split()] -ans = 0 -for cmb in range(0, 2**N): -    b = list(str(bin(cmb)))[2:] -    cmb_b = ["0"] * (N - len(b)) + b -    cur_cnd = [0] * M -    for s_cnd, i in zip(reversed(cmb_b), list(range(N))): -        for s, j in zip(S, list(range(M))): -            if s_cnd == "1" and s[i]: -                cur_cnd[j] = (cur_cnd[j] + 1) % 2 -    if P == cur_cnd: -        ans += 1 -print(ans) +import sys + +input = sys.stdin.readline + + +def make_switch_set(i, s): +    if i == N: +        return [s] +    else: +        cs = s.copy() +        cs.add(i + 1) +        return make_switch_set(i + 1, s) + make_switch_set(i + 1, cs) + + +def main(): +    ans = 0 +    for ss in switch_set: +        count = 0 +        for switches, p in zip(S, P): +            match_num = len(ss & switches) +            if match_num % 2 == p: +                count += 1 +        if count == M: +            ans += 1 +    print(ans) + + +if __name__ == "__main__": +    N, M = list(map(int, input().split())) +    S = [] +    for _ in range(M): +        ipts = [int(ipt) for ipt in input().split()] +        S.append(set(ipts[1:])) +    P = [int(p) for p in input().split()] +    switch_set = make_switch_set(0, set()) +    main()