import itertools
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, M = input().split()
N = int(N)
M = int(M)
S_list = []
S_list = []
for h in range(M):
    list = []
    list = input().split()
    for y in range(int(len(list[0]))):
        s_list[y] = list[y+1]
        S_list.append(s_list)
p_list = []
p_list = input().split()
p_list = [int(s) for s in p_list]


count = 1

for i in range(M):
    if p_list[i] == 0:
        x = int(k_list[i]/2 + 1)
        for l in range(x):
            c = list(itertools.combinations(S_list[i],2*l))
            count = count*len(c)
    else:
        x = int((k_list[i]-1)/2 + 1)
        for l in range(x):
            c = list(itertools.combinations(S_list[i],2*l+1))
            count = count*len(c)

print(count)
