n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(list(map(int, input().split())))
    a[i] = a[i][1:]
p = list(map(int, input().split()))
light = [False] * n
judge = [False] * m
ans = 0
rank = [0] * m
def dfs(step):
    global ans
    if False not in judge:
        if step < n:
            ans += 2**(n-step)
        else:
            ans += 1
    for k in range(step, n):
        light[k] = True
        for j in range(m):
            if k + 1 in a[j]:
                rank[j] ^= 1
                if rank[j] == p[j]:
                    judge[j] = True
                else:
                    judge[j] = False
        dfs(k + 1)
        light[k] = False
dfs(0)
print(ans)