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

ss = []

for mi in range(m):

  splus = [0]*n

  s = list(map(int,input().split()))[1:]

  for ni in range(n):

    if (ni+1) in s:

      splus[ni] = 1

  ss.append(splus)

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

score = 0

swi = [0]*n

while True:

  judge = 1

  for mi in range(m):

    count = 0

    for ni in range(n):

      count += ss[mi][ni] * swi[ni]

    judge *= bool(count%2==p[mi])

  if judge == 1:

    score += 1

  swi[0] +=1

  for ni in range(n-1):

    if swi[ni] == 2:

      swi[ni] = 0

      swi[ni+1] += 1

  if swi[-1] == 2:

    break

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

time = [0 for _ in range(n)]

def nex(time):

  for i in range(n):

    if time[i] == 0:

      time[i] += 1

      break

    else:

      time[i] = 0

  else:

    time = 'over'

  return time

s = []

for _ in range(m):

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

  add = [0 for _ in range(n)]

  for j in range(1,raw[0]+1):

    add[raw[j]-1] = 1

  s.append(add)

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

ans = 0

while time != 'over':

  for k in range(m):

    tmp = p[k]

    for i in range(n):

      tmp ^= time[i] * s[k][i]

    if tmp == 1:

      break

  else:

    ans += 1

  time = nex(time)

print(ans)
n, m = list(map(int, input().split()))
ss = []
for mi in range(m):
    splus = [0] * n
    s = list(map(int, input().split()))[1:]
    for ni in range(n):
        if (ni + 1) in s:
            splus[ni] = 1
    ss.append(splus)
p = list(map(int, input().split()))
score = 0
swi = [0] * n
while True:
    judge = 1
    for mi in range(m):
        count = 0
        for ni in range(n):
            count += ss[mi][ni] * swi[ni]
        judge *= bool(count % 2 == p[mi])
    if judge == 1:
        score += 1
    swi[0] += 1
    for ni in range(n - 1):
        if swi[ni] == 2:
            swi[ni] = 0
            swi[ni + 1] += 1
    if swi[-1] == 2:
        break
print(score)

n, m = list(map(int, input().split()))
time = [0 for _ in range(n)]


def nex(time):
    for i in range(n):
        if time[i] == 0:
            time[i] += 1
            break
        else:
            time[i] = 0
    else:
        time = "over"
    return time


s = []
for _ in range(m):
    raw = list(map(int, input().split()))
    add = [0 for _ in range(n)]
    for j in range(1, raw[0] + 1):
        add[raw[j] - 1] = 1
    s.append(add)
p = list(map(int, input().split()))
ans = 0
while time != "over":
    for k in range(m):
        tmp = p[k]
        for i in range(n):
            tmp ^= time[i] * s[k][i]
        if tmp == 1:
            break
    else:
        ans += 1
    time = nex(time)
print(ans)

-ss = [] -for mi in range(m): -    splus = [0] * n -    s = list(map(int, input().split()))[1:] -    for ni in range(n): -        if (ni + 1) in s: -            splus[ni] = 1 -    ss.append(splus) +time = [0 for _ in range(n)] + + +def nex(time): +    for i in range(n): +        if time[i] == 0: +            time[i] += 1 +            break +        else: +            time[i] = 0 +    else: +        time = "over" +    return time + + +s = [] +for _ in range(m): +    raw = list(map(int, input().split())) +    add = [0 for _ in range(n)] +    for j in range(1, raw[0] + 1): +        add[raw[j] - 1] = 1 +    s.append(add) -score = 0 -swi = [0] * n -while True: -    judge = 1 -    for mi in range(m): -        count = 0 -        for ni in range(n): -            count += ss[mi][ni] * swi[ni] -        judge *= bool(count % 2 == p[mi]) -    if judge == 1: -        score += 1 -    swi[0] += 1 -    for ni in range(n - 1): -        if swi[ni] == 2: -            swi[ni] = 0 -            swi[ni + 1] += 1 -    if swi[-1] == 2: -        break -print(score) +ans = 0 +while time != "over": +    for k in range(m): +        tmp = p[k] +        for i in range(n): +            tmp ^= time[i] * s[k][i] +        if tmp == 1: +            break +    else: +        ans += 1 +    time = nex(time) +print(ans)