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

ks = [list(map(int, input().split())) for i in range(m)]

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

ans = 0

for i in range(2 ** n):

  onswichi = [False] * n

  onlight = [0] * m

  for j in range(n):

    if (i >> j) & 1:

      onswichi[j] = True

  for k in range(m):

    cnt = 0

    for f in ks[k][1:]:

      if onswichi[f-1]:

        cnt += 1

    if cnt % 2 == p[k]:

      onlight[k] = 1

  if sum(onlight) == m:

    ans += 1

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

ks = [list(map(int, input().split())) for i in range(m)]

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

ans = 0

for i in range(2**n):

    l = [False] * n

    for j in range(n):

        if (i>>j) & 1:

            l[j] = True

    for j in range(m):

        if [l[k-1] for k in ks[j][1:]].count(True) % 2 != p[j]:

            break

    else:

        ans += 1

print(ans)
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    onswichi = [False] * n
    onlight = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            onswichi[j] = True
    for k in range(m):
        cnt = 0
        for f in ks[k][1:]:
            if onswichi[f - 1]:
                cnt += 1
        if cnt % 2 == p[k]:
            onlight[k] = 1
    if sum(onlight) == m:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    l = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            l[j] = True
    for j in range(m):
        if [l[k - 1] for k in ks[j][1:]].count(True) % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

-    onswichi = [False] * n -    onlight = [0] * m +    l = [False] * n -            onswichi[j] = True -    for k in range(m): -        cnt = 0 -        for f in ks[k][1:]: -            if onswichi[f - 1]: -                cnt += 1 -        if cnt % 2 == p[k]: -            onlight[k] = 1 -    if sum(onlight) == m: +            l[j] = True +    for j in range(m): +        if [l[k - 1] for k in ks[j][1:]].count(True) % 2 != p[j]: +            break +    else: