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



lights = []

for _ in range(M):

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

    mask = 0

    for a in S[1:]:

        mask |= (1 << (a - 1))

    lights.append(mask)



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



ans = 0

for mask in range(1 << N):

    for state, p in zip(lights, P):

        cnt = 0

        for d in range(N):

            if ((1 << d) & state) > 0 and ((1 << d) & mask) > 0:

                cnt += 1

        if cnt % 2 != p:

            break

    else:

        ans += 1



print(ans)

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



S = []

for _ in range(M):

    s = tuple([int(a) - 1 for a in input().split()])[1:]

    S.append(s)



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



ans = 0

for state in range(1 << N):

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

        cnt = 0

        for i in s:

            cnt += 1 if (state & (1 << i)) > 0 else 0

        if cnt % 2 != p:

            break

    else:

        ans += 1



print(ans)

N, M = list(map(int, input().split()))
lights = []
for _ in range(M):
    S = list(map(int, input().split()))
    mask = 0
    for a in S[1:]:
        mask |= 1 << (a - 1)
    lights.append(mask)
P = list(map(int, input().split()))
ans = 0
for mask in range(1 << N):
    for state, p in zip(lights, P):
        cnt = 0
        for d in range(N):
            if ((1 << d) & state) > 0 and ((1 << d) & mask) > 0:
                cnt += 1
        if cnt % 2 != p:
            break
    else:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    s = tuple([int(a) - 1 for a in input().split()])[1:]
    S.append(s)
P = tuple(map(int, input().split()))
ans = 0
for state in range(1 << N):
    for p, s in zip(P, S):
        cnt = 0
        for i in s:
            cnt += 1 if (state & (1 << i)) > 0 else 0
        if cnt % 2 != p:
            break
    else:
        ans += 1
print(ans)

-lights = [] +S = [] -    S = list(map(int, input().split())) -    mask = 0 -    for a in S[1:]: -        mask |= 1 << (a - 1) -    lights.append(mask) -P = list(map(int, input().split())) +    s = tuple([int(a) - 1 for a in input().split()])[1:] +    S.append(s) +P = tuple(map(int, input().split())) -for mask in range(1 << N): -    for state, p in zip(lights, P): +for state in range(1 << N): +    for p, s in zip(P, S): -        for d in range(N): -            if ((1 << d) & state) > 0 and ((1 << d) & mask) > 0: -                cnt += 1 +        for i in s: +            cnt += 1 if (state & (1 << i)) > 0 else 0