import itertools

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


for i in range(n):
    s[i].sort()

cnt = 0
for i in range(2 ** n):
    STATE = []
    digit = len(format(i, 'b'))
    N = int(format(i, 'b'))
    for j in range(digit):
        if ((i >> j) & 1):
            STATE.append(j + 1)
    for k in range(m):
        tmp = []
        if p[k] == 1:
            for l in range(1, len(s), 2):  
                for o, _ in enumerate(s, l):
                    for p in itertools.permutations(s, o):
                        tmp.append(o)
        else:
            for l in range(2, len(s), 2):
                for o in enumerate(s,l):
                    for p in itertools.permurtations(s, o):
                        tmp.append(o)
        if STATE == tmp:
            cnt += 1
print(cnt)
