import itertools

n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    array = list(map(int, input().split()))
    k.append(array.pop(0))
    s.append(array)
p = list(map(int, input().split()))

for i in range(m):
    s[i].sort()
ans = 0
cnt = 0
for i in range(2 ** n):
    STATE = []
    digit = len(format(i, 'b'))
    for j in range(digit):
        if ((i >> j) & 1):
            STATE.append(j + 1)
    for l in range(m):
        if p[l] == 1:
            for o in range(1, len(s[l]) + 1, 2):  
                for r in itertools.combinations(s[l], o):
                    if set(r) == set(STATE):
                        cnt += 1
        else:   
            for o in range(2, len(s[l]) + 1, 2):
                for r in itertools.combinations(s[l], o):
                    if set(r) == set(STATE):
                        cnt += 1
    if cnt == m:
        ans += 1
print(ans)
