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

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

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



ans=0

for i in range(2**n):

  num=0

  #ある電球

  for j in range(m):

    cnt=0

    #ある電球に接続されている各スイッチ

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

      if (i>>l[j][k]-1) & 1:

        cnt+=1

    if cnt%2==p[j]:

      num+=1

  if num==m:

    ans+=1



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

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

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



cnt=0

for i in range(2**n):

  l=[0 for j in range(n)]

  for j in range(n):

    if (i>>j)&1:

      l[j]=1



  t_cnt=0

  for j in range(m):

    on_l=0

    for x in k[j][1:]:

      x-=1

      if l[x]==1:

        on_l+=1

    if on_l%2==p[j]:

      t_cnt+=1



  if t_cnt==m:

    cnt+=1



print(cnt)
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    num = 0
    # ある電球
    for j in range(m):
        cnt = 0
        # ある電球に接続されている各スイッチ
        for k in range(1, l[j][0] + 1):
            if (i >> l[j][k] - 1) & 1:
                cnt += 1
        if cnt % 2 == p[j]:
            num += 1
    if num == m:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
k = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
cnt = 0
for i in range(2**n):
    l = [0 for j in range(n)]
    for j in range(n):
        if (i >> j) & 1:
            l[j] = 1
    t_cnt = 0
    for j in range(m):
        on_l = 0
        for x in k[j][1:]:
            x -= 1
            if l[x] == 1:
                on_l += 1
        if on_l % 2 == p[j]:
            t_cnt += 1
    if t_cnt == m:
        cnt += 1
print(cnt)

-l = [list(map(int, input().split())) for i in range(m)] +k = [list(map(int, input().split())) for i in range(m)] -ans = 0 +cnt = 0 -    num = 0 -    # ある電球 +    l = [0 for j in range(n)] +    for j in range(n): +        if (i >> j) & 1: +            l[j] = 1 +    t_cnt = 0 -        cnt = 0 -        # ある電球に接続されている各スイッチ -        for k in range(1, l[j][0] + 1): -            if (i >> l[j][k] - 1) & 1: -                cnt += 1 -        if cnt % 2 == p[j]: -            num += 1 -    if num == m: -        ans += 1 -print(ans) +        on_l = 0 +        for x in k[j][1:]: +            x -= 1 +            if l[x] == 1: +                on_l += 1 +        if on_l % 2 == p[j]: +            t_cnt += 1 +    if t_cnt == m: +        cnt += 1 +print(cnt)