N, M = map(int, input().split())
K = []
S = []
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    S.append(l)
P = list(map(int, input().split()))
ans = 0
for n in range(1<<N):
    print(n)
    res = True
    for m in range(M):
        cnt = 0
        for q in range(K[m]):
            if n & (1<<S[m][q]-1):
                cnt += 1
        if cnt % 2 != P[m]:
            res = False
    if res:
        ans += 1
print(ans)
