import itertools
N, M = map(int, input().split())
list1 = []
kli = []
for i in range(M):
    cur_li = list(map(int, input().split()))
    list1.append(cur_li[1:])
    kli.append(cur_li[0])
pli = list(map(int,input().split()))
anslist = []
kosu_g = []
kosu_k = []
if pli[0] == 0:
    for i in range(1,N):
        if i%2 ==0:
            kosu_g.append(i)
    for i in kosu_g:
        c_list = list(itertools.combinations(list1[0], i))
        anslist = anslist + c_list
if pli[0] == 1:
    for i in range(1,N):
        if i%2 ==1:
            kosu_k.append(i)
    for i in kosu_k:
        c_list = list(itertools.combinations(list1[0], i))
        anslist = anslist + c_list
    anslist.append([""])
for i in range(1,M):
    curlist =[]
    if pli[i] == 0:
        for j in kosu_g:
            c_list = list(itertools.combinations(list1[i], j))
            curlist = curlist + c_list
        curlist.append([""])
        for j in anslist:
            if j in curlist:
                pass
            else:
                anslist.remove(j)
    if pli[i] == 1:
        for j in kosu_k:
            c_list = list(itertools.combinations(list1[i], j))
            curlist = curlist + c_list
        for j in anslist:
            if j in curlist:
                pass
            else:
                anslist.remove(j)
print(len(anslist))