import copy
class Lamp:

    def __init__(self, id, connected_switches):
        self.id = id
        self.on_number = 0
        self.connected_switches = connected_switches
        self.connected_number = len(connected_switches)

    def set_on_number(self, on_number):
        self.on_number = on_number


inp = input()
st = inp.split()
n = int(st[0])
m = int(st[1])
lamp_dictionary = {}
lamp_list = []
for i in range(m):
    inp = input()
    st = inp.split()
    k = int(st[0])
    connected_switches = []
    for j in range(k):
        s = int(st[j+1])
        connected_switches.append(s)
    lamp_list.append(Lamp(i+1, connected_switches))
# input p
inp = input()
st = inp.split()
for i in range(m):
    p = int(st[i])
    lamp_c = lamp_list[i]
    lamp_c.set_on_number(p)
    k = lamp_c.connected_number
    if k in lamp_dictionary:
        lamps = lamp_dictionary[k]
        lamps.append(lamp_c)
    else:
        lamp_dictionary[k] = [lamp_c]

lamp_sorted_list = sorted(lamp_dictionary.keys())  # つながっているスイッチの少ない順
lamps_list = []  # 小さい順に並べたlampのりすと
for connected_number in lamp_sorted_list:
    lamps = lamp_dictionary[connected_number]
    for lamp in lamps:
        lamps_list.append(lamp)
# スウイッチを決定していく
switch_list = [0 for _ in range(n+1)]  # 0:not decided 1:on 2:off

def decide_switch(i):
    # 可能な数を返す
    if i == len(lamps_list):
        return 1
    lamp = lamps_list[i]
    able_decide_switches = []
    on_count = 0
    for switch in lamp.connected_switches:
        if switch_list[switch] == 0:
            able_decide_switches.append(switch)
        elif switch_list[switch] == 1:
            on_count += 1
    # 少なくとも可能なスイッチのパターが一つあれば次のランプを調べる
    p = lamp.on_number
    if not able_decide_switches:
        if on_count % 2 == p:
            return decide_switch(i+1)
        else:
            return 0
    else:
        # スイッチを変えられる.変えられる可能性すべてを調べる
        changing_list = make_list([], 1, len(able_decide_switches))
        total_able_change_count = 0
        if not changing_list:
            print("")
        for chang in changing_list:
            count = on_count
            for num in chang:
                count += num
            if count % 2 == p:
                # 次のランプを調べる
                for inde, num in enumerate(chang):
                    v = num
                    if num == 0:
                        v = 2
                    switch_list[able_decide_switches[inde]] = v
                total_able_change_count += decide_switch(i+1)
                # すいっちを0にもどす
                for inde, num in enumerate(chang):
                    switch_list[able_decide_switches[inde]] = 0
        return total_able_change_count


def make_list(l, i, max_n):
    ol = copy.deepcopy(l)
    il = copy.deepcopy(l)
    ol.append(0)
    il.append(1)
    if i == max_n:
        return [ol, il]
    ooo = make_list(ol, i+1, max_n)
    iii = make_list(il, i+1, max_n)
    for ii in iii:
        ooo.append(ii)
    return ooo
    # return make_list(ol, i+1, max_n).extend(make_list(il, i+1, max_n))

ans = decide_switch(0)
print(int(ans/2))
