CodeEff/ECCO huggingface dataset:
# Original solution
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(1<<N):
    flag = True
    for j in range(M):
        s = ks[j][1:]
        count = 0
        for v in s:
            if i & (1<<(v-1)):
                count += 1
        if count % 2 != p[j]:
            flag = False
    
    if flag:
        ans += 1

print(ans)


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

s = []
for i in range(m):
    s.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(1<<n):
    isOn = []
    for j in range(n):
        if i & (1<<j):
            isOn.append(j+1)

    flag = True
    for j in range(m):
        count = 0
        for v in s[j]:
            if v in isOn:
                count += 1
        if count % 2 != p[j]:
            flag = False
    if flag:
        ans += 1

print(ans)
# Original solution
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
# print(N, M)
# print(ks)
# print(p)

ans = 0

import itertools
for i in itertools.product([0,1], repeat=N):
  righted = 0
  for iter, j in enumerate(ks):
  #  print(iter, j )
    cnt = 0
    for k in range(1,len(j)):
      cnt += i[j[k]-1]
    if cnt % 2 == p[iter]:
      righted += 1
  if len(ks) == righted:
    ans += 1
    
print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
  
ans = 0
for b in range(2 ** n):
  onswitch = [i + 1 for i in range(n) if (b >> i) & 1]
  if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):
    ans += 1
    
print(ans)
# Original solution
N, M = list(map(int, input().split()))
k = [input().split() for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for n in range(2 ** N):
    is_mismatch = False
    for i in range(M):
        cnt = 0
        for si in k[i][1:]:
            if (n >> (int(si) - 1)) & 1:
                cnt = (cnt + 1) % 2
        if cnt != p[i]:
            is_mismatch = True
            break
    if not is_mismatch:
        ans += 1
    
print(ans)
    

# Optimized solution
n, m = list(map(int, input().split()))
swtiches = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2 ** n):
    is_on = True
    for j in range(m):
        k = swtiches[j][0]
        s = swtiches[j][1:]
        cnt = 0
        for si in s:
            if i >> (si - 1) & 1:
                cnt += 1
        if cnt % 2 != p[j]:
            is_on = False
    if is_on:
        ans += 1

print(ans)
# Original solution
N, M = list(map(int,input().split()))
K = []
S = []
for _ in range(M):
    KS = list(map(int,input().split()))
    k = KS.pop(0)
    K.append(k)
    S.append(KS)
P = list(map(int,input().split()))

cnt = 2 ** N
ans = 0

for i in range(cnt):
    flg = 1
    for j in range(M):
        s = S[j]
        sum_s = 0
        for x in s:
            sum_s += 2 ** (x - 1)
        calc = sum_s & i
        sum_str = bin(calc)
        div = sum_str.count('1') % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

# Optimized solution
N, M = list(map(int,input().split()))
K = []
S = []
for _ in range(M):
    KS = list(map(int,input().split()))
    k = KS.pop(0)
    K.append(k)
    S.append(KS)
P = list(map(int,input().split()))

cnt = 2 ** N
ans = 0

sum = [0] * M

for j in range(M):
    for x in S[j]:
        sum[j] += 2 ** (x - 1)

for i in range(cnt):
    flg = 1
    for j in range(M):
        calc = sum[j] & i
        sum_str = bin(calc)
        div = sum_str.count('1') % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)
# Original solution
n, m = list(map(int, input().split()))
s = []
for i in range(m):
    inputs = list(map(int, input().split()))
    k = inputs[0]
    s.append(inputs[1:])

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

res = 0
for i in range(2 ** n):
    flag = True
    bit_i = bin(i)[2:].zfill(n)
    for j in range(m):
        sum_s = 0
        for idx in s[j]:
            sum_s += int(bit_i[idx-1])
        if sum_s % 2 != p[j]:
            flag = False
            break
    if flag:
        res += 1

print(res)

# Optimized solution
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    ks = list(map(int, input().split()))
    S.append(ks[1:])
P = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    bi = str(bin(i))[2:]
    bi = bi.zfill(N)
    isAddable = True
    for j in range(M):
        s_sum = 0
        for s in S[j]:
            if bi[s-1] == '1':
                s_sum += 1
        if s_sum % 2 != P[j]:
            isAddable = False
            break
    if isAddable:
        ans += 1
print(ans)
# Original solution
N, M = list(map(int, input().split()))
k = [0]*M
s = [""]*M
for i in range(M):
    tmp = list(map(int, input().split()))
    k[i] = tmp[0]
    s[i] = tmp[1:]

p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    global_count = 0
    for j in range(M):
        local_count = 0
        for x in s[j]:
            if (i >> (x - 1)) % 2 == 0:
                continue
            else:
                local_count += 1
        if local_count % 2 == p[j]:
            global_count += 1
    if global_count == M:
        ans += 1

print(ans)


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


K = [[0]*N for i in range(M)]


for i in range(M):
    tmp = list(map(int, input().split()))
    for j in tmp[1:]:
        K[i][j-1] = 1
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    tmp = [0]*M
    for j in range(N):
        if (i >> j) % 2 == 1:
            for k in range(M):
                tmp[k] += K[k][j]
    for j in range(M):
        if tmp[j] % 2 != p[j]:
            break
        if j == M-1:
            ans += 1


print(ans)
# Original solution
N,M=list(map(int,input().split()))
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    for m in range(M):
        switch=0
        for j in range(N):
            if (i>>j)&1 and j+1 in s[m]:
                switch+=1
        if switch%2!=p[m]:
            break
    else:
        count+=1
print(count)

# Optimized solution
N, M = list(map(int, input().split()))
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** N):
    for m in range(M):
        switch = 0
        for j in range(N):
            if (i >> j) & 1:
                if j + 1 in s[m]:
                    switch += 1
        if switch % 2 != p[m]:
            break
    else:
        count += 1
print(count)
# Original solution
'''
https://atcoder.jp/contests/abc128/tasks/abc128_c
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque

    #mod = 1000000007

    n, m = list(map(int, input().split()))
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        cnt = 0
        for i in range(m):
            total = 0
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if total%2 == p[i]:
                cnt += 1
            else:
                break
        if cnt == m:
            ret += 1
    print(ret)
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n, m = list(map(int, input().split()))
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        for i in range(m):
            total = 0
            flag = 1
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if not total%2 == p[i]:
                flag = 0
                break
        if flag:
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))
bulbs = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    bulbs.append((k, s))
p = list(map(int, input().split()))

ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                if j + 1 in bulbs[k][1]:
                    on_cnt[k] = (on_cnt[k] + 1) % 2
    if on_cnt == p:
        ans += 1
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
bulbs = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    bulbs.append((k, s))
p = list(map(int, input().split()))

ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                if j + 1 in bulbs[k][1]:
                    on_cnt[k] ^= 1
    if on_cnt == p:
        ans += 1
print(ans)
# Original solution
n,m=list(map(int,input().split()))
ans=0
e=[set(list(map(int,input().split()))[1:]) for i in range(m)]
f=list(map(int,input().split()))
for i in range(2**n):
  l={a for a,b in zip(list(range(1,n+1)),bin(i)[2:].zfill(n)) if b=="1"}
  for j in range(1,m+1):
    if len(e[j-1]&l)%2!=f[j-1]:break
  else:ans+=1
print(ans)

# Optimized solution
def ma():
  n,m=list(map(int,input().split()))
  ans=0
  e=[set(list(map(int,input().split()))[1:]) for i in range(m)]
  f=list(map(int,input().split()))
  for i in range(2**n):
    l={a for a,b in zip(list(range(1,n+1)),bin(i)[2:].zfill(n)) if b=="1"}
    for j in range(1,m+1):
      if len(e[j-1]&l)%2!=f[j-1]:break
    else:ans+=1
  print(ans)

if __name__=="__main__":
  ma()
# Original solution
def ma():
  n,m=list(map(int,input().split()))
  ans=0
  e=[set(list(map(int,input().split()))[1:]) for i in range(m)]
  f=list(map(int,input().split()))
  for i in range(2**n):
    l={a for a,b in zip(list(range(1,n+1)),bin(i)[2:].zfill(n)) if b=="1"}
    if sum([int(len(e[j-1]&l)%2 !=f[j-1]) for j in range(1,m+1)])==0:ans+=1
  print(ans)

if __name__=="__main__":
  ma()

# Optimized solution
def ma():
  n,m=list(map(int,input().split()))
  ans=0
  e=[set(list(map(int,input().split()))[1:]) for i in range(m)]
  f=list(map(int,input().split()))
  for i in range(2**n):
    l={a for a,b in zip(list(range(1,n+1)),bin(i)[2:].zfill(n)) if b=="1"}
    if sum({int(len(e[j-1]&l)%2 !=f[j-1]) for j in range(1,m+1)})==0:ans+=1
  print(ans)

if __name__=="__main__":
  ma()
# Original solution
N, M = list(map(int, input().split()))
lights = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0

for i in range(1<<N):
    on = 0
    onoff = bin(i)[2:].zfill(N)
    for j, switches in enumerate(lights):
        if sum(onoff[s-1] == '1' for s in switches[1:]) % 2 == p[j]:
            on += 1
    if on == M:
        ans += 1

print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
connected = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0

for i in range(1<<N):
    for j,lst in enumerate(connected):
        count = 0
        for s in lst[1:]:
            if (i>>(s-1)) & 1:
                count += 1
        if count % 2 != p[j]:
            break
    else:
        ans += 1

print(ans)
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n,m=LI()

  l=[]
  for _ in range(m):
    a=LI()
    l.append(a[1:])

  l2=LI()

  pattern=[]
  for i in range(1<<n):
    _l=[]
    for j in range(n):
      _l.append(1 if i&(1<<j) else 0)
    pattern.append(_l)

  ans=0
  for x in pattern:
    f=True
    for i,y in enumerate(l):
      on_num=0
      for z in y:
        on_num+=x[z-1]

      if not f:
        break
      if f and l2[i]!=on_num%2:
        f=False
        break

    if f:
      ans+=1

  return ans

# main()
print((main()))


# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n,m=LI()
  l=[]
  for _ in range(m):
    a=LI()
    l.append(a[1:])

  lp=LI()

  a=[]
  for i in range(1<<n):
    _a=[]
    for j in range(n):
      if i&(1<<j):
        _a.append(1)
      else:
        _a.append(0)
    a.append(_a)

  ans=0
  for x in a:
    f=True
    for i,y in enumerate(l):
      _sum=0
      for z in y:
        _sum+=x[z-1]
      if _sum%2!=lp[i]:
        f=False
        break
    if f:
      ans+=1

  return ans

# main()
print((main()))
# Original solution
import itertools
N,M=list(map(int,input().split()))
kslist=[]
for i in range(M):
    kslist.append(list(map(int,input().split()))) 
plist=list(map(int,input().split()))
seq=[0]*N+[1]*N
ls=list(set(list(itertools.permutations(seq,N))))
n=0
for tup in ls:
    ln=[]
    for j in range(M):
        sum1=0
        for k in range(1,kslist[j][0]+1):
            sum1+=tup[kslist[j][k]-1]
        ln.append(sum1%2)
    if ln==plist:
        n+=1
        
print(n)            
    


# Optimized solution
import itertools
N,M=list(map(int,input().split()))
kslist=[(list(map(int,input().split()))) for i in range(M)]
plist=list(map(int,input().split()))
ls=list((itertools.product(list(range(2)),repeat=N)))
n=0
for tup in ls:
    n+=1
    for j in range(M):
        sum1=0
        for k in range(1,kslist[j][0]+1):
            sum1+=tup[kslist[j][k]-1]
        if sum1%2!=plist[j]:
            n=n-1
            break
print(n)
# Original solution
n,m=list(map(int,input().split()))
switch=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    cnt=[0]*m
    for j in range(n):
        if (i>>j)&1==1:
            for k in range(m):
                if j+1 in switch[k][1:]:
                    cnt[k]+=1
    l=[i%2 for i in cnt]
    if l==p:
        ans+=1
print(ans)

# Optimized solution
n,m=list(map(int,input().split()))
s=[list(map(int,input().split()))[1:] for _ in range(m)]
p=list(map(int,input().split()))
ans=0

for i in range(2**n):
    tmp=[]
    cnt=[0]*n
    for j in range(n):
        if (i>>j)&1:
            tmp.append(j+1)
    for k in range(m):
        if len(set(tmp)&set(s[k]))%2!=p[k]:
            break
    else:
        ans+=1
print(ans)
# Original solution
n,m=list(map(int,input().split()))
s=[]
for _ in range(m):
    _,*t=list(map(int,input().split()))
    s.append(t)
p=list(map(int,input().split()))
a=0
for i in range(2**n):
    f=1
    for j in range(m):
        g=1
        g&=(sum([int(bin(i>>(u-1)),2) for u in s[j]])%2==p[j])
        f&=g
    a+=f
print(a)

# Optimized solution
n,m=list(map(int,input().split()))
s=[]
for _ in range(m):_,*t=list(map(int,input().split()));s.append(t)
*p,=list(map(int,input().split()))
print((sum([all([sum([i>>(u-1)for u in s[j]])%2==p[j]for j in range(m)])for i in range(2**n)])))
# Original solution
# bit演算
N, M = list(map(int, input().split()))
# 各スイッチがどの電球に繋がっているかをbitで持つ
# スイッチ1が電球1、電球2に繋がっている場合は
# 101 -> 5 という持ち方
a = [0] * N
for i in range(M):
    K, *S = list(map(int, input().split()))
    for j in range(K):
        s = S[j]
        s -= 1
        # s番目のスイッチにi番目の電球が繋がっている
        a[s] |= 1 << i

expected = 0
l = list(map(int, input().split()))
for i in range(M):
    expected |= l[i] << i

# on/offの2通り、スイッチは最大10個なので、# 2^10=1024で全通り試してもOK
# on/offの全ての組み合わせをbitでループする
ans = 0
for s in range(1 << N):
    # 各電球の状態(bit)
    lighting = 0
    for i in range(N):
        # iビット目が立っているか
        if s >> i & 1:
            # スイッチを押して、つながった電球の状態を反転させる
            lighting ^= a[i]
    # 各スイッチを押した後の電球の状態が理想と一致するか
    if lighting == expected:
        ans += 1

print(ans)


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

a = [0] * N
for i in range(M):
    K, *S = list(map(int, input().split()))
    for j in range(K):
        s = S[j]
        s -= 1
        # s番目のスイッチにi番目の電球が繋がっている
        a[s] |= 1 << i

expected = 0
P = list(map(int, input().split()))
for i in range(M):
    if P[i]:
        expected |= 1 << i

ans = 0
for s in range(1 << N):  # スイッチの状態
    tmp = 0
    for i in range(N):
        if s >> i & 1:
            tmp ^= a[i]
    if tmp == expected:
        ans += 1

print(ans)
# Original solution
import itertools
n, m = list(map(int, input().split()))
switches = []
for i in range(m):
    line = list(map(int, input().split()))
    switches.append(line[1:])
p = list(map(int, input().split()))

# スイッチに関して全探索
ans = 0
for item in itertools.product([0, 1], repeat=n):
    flag = True
    for i, switch in enumerate(switches):
        on_count = 0
        for s in switch:
            on_count += item[s-1]
        if on_count % 2 != p[i]:
            flag = False
    if flag: ans += 1
print(ans)


# Optimized solution
import itertools
n, m = list(map(int, input().split()))
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for item in itertools.product([0, 1], repeat=n):
    for i in range(m):
        if sum([item[j-1] for j in s[i]]) % 2 != p[i]:
            break
    else:
        ans += 1
print(ans)
# Original solution
import itertools

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

S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

# Optimized solution
import itertools
 
N, M = list(map(int, input().split()))
 
S = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    S.append(s)
    
P = [int(i) for i in input().split()]
 
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)
# Original solution
import sys
input = sys.stdin.readline

from itertools import product

N,M = list(map(int,input().split()))
S = [list(map(int,input().split()))[1:] for _ in range(M)]
P = list(map(int,input().split()))

ans = 0
for p in product([0,1],repeat=N):
    can = 0
    for i in range(M):
        res = 0
        for s in S[i]:
            if p[s-1] == 1:
                res += 1
        res %= 2
        if res == P[i]:
            can += 1
    if can == M:
        ans += 1

print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
S = [list(map(int,input().split()))[1:] for _ in range(M)]
P = list(map(int,input().split()))

ans = 0

for mask in range(0,1<<N):
    flag = True
    for i, line in enumerate(S):
        cnt = 0
        for s in line:
            if ((mask >> (s-1) & 1)):
                cnt += 1
        if cnt % 2 != P[i]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)
# Original solution
from sys import stdin
from itertools import combinations_with_replacement,product

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
p = list(map(int,stdin.readline().rstrip().split()))

hai = [0,1]
hai = list(product(hai, repeat=n))

point = 0

for i in range(len(hai)):
    h = list(hai[i])
    kai = 0
    for j in range(m):
        gou = 0
        for k in range(1,len(li[j])):
            if h[li[j][k]-1] == 1:
                gou += 1
        if p[j] != gou%2:
            kai += 1
    if kai == 0:
        point += 1
print(point)

# Optimized solution
n,m = list(map(int,input().split()))
li = [list(map(int,input().split()))[1:] for _ in range(m)]
p = list(map(int,input().split()))
ans = 0

for i in range(1 << n):
    switch = set()
    for j in range(n):
        if (i >> j)&1:
            switch.add(j+1)
    for k in range(m):
        point = 0
        for l in li[k]:
            if l in switch:
                point += 1
        if point%2 != p[k]:
            break
    else:
        ans += 1

print(ans)
# Original solution
import itertools

N, M = list(map(int, input().split()))
lights = []
for i in range(M):
    lights.append([int(x) for x in input().split()])
p = [int(x) for x in input().split()]

ans = 0
switches = 0b1111111111 >> (10 - N)
for _ in range(0, switches + 1):
    flag = True
    for i in range(M):
        s = 0
        for j in range(1, lights[i][0] + 1):
            s += (_ & (0b1 << (lights[i][j] - 1))) >> (lights[i][j] - 1)
        if s % 2 != p[i]:
            flag = False
    if flag:
        ans += 1

print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
lights = []
for _ in range(M):
    lights.append([int(i) for i in input().split()])
p = [int(i) for i in input().split()]

ans = 0
for switch in range(0, 2**N):
    flag = True
    for i in range(M):
        s = 0
        for j in range(lights[i][0]):
            s += (switch >> (lights[i][j + 1] - 1)) & 0b1
        if s % 2 != p[i]:
            flag = False
    if flag:
        ans += 1

print(ans)
# Original solution
N,M = list(map(int,input().split()))
in_M =[[]]*M 
for m in range(M):
    in_M[m] = list(map(int,input().split()))
out_M = list(map(int,input().split()))

all_on_cnt = 0
for i in range(2**N):
    switch = [0]*N
    for j in range(N):
        if((i>>j) & 1): # iをj回右シフトさせ末尾をみる
            switch[j] = 1
    
    for j in range(M):
        total = 0
        for l in range(1,in_M[j][0]+1):
            total += switch[in_M[j][l]-1]
        if total%2 != out_M[j]:
            break
    else:
        all_on_cnt += 1
          
print(all_on_cnt)        

# Optimized solution
n,m = list(map(int,input().split()))
swi = []
for _ in range(m):
    k, *sss = list(map(int,input().split()))
    t = 0
    for s in sss:
        t += 1 << (s-1)
    swi.append(t)
ppp = list(map(int,input().split()))

ans = 0
for bit in range(1<<n):
    for s,p in zip(swi,ppp):
        t = bit&s
        c = bin(t).count("1") % 2
        if c != p:
            break
    else:
        ans += 1
print(ans)
# Original solution
n=int(eval(input()));result=[]
while n!=0:
  r=n%2
  n=(n-r)//-2
  result.append(r)
print((''.join(map(str,(result[::-1]))) if result else 0))

# Optimized solution
n=int(eval(input()));result=[]
while n!=0:
  r=n%2
  n=(n-r)//-2
  result.append(r)
print((''.join(map(str,result[::-1])) if result else 0))