def bits2tuple(n):
    ret = []
    i = 0
    while (1 << i) <= n:
        if n & (1 << i) != 0:
            ret.append(i)
        i += 1
    return tuple(ret)


def main():
    N, M = map(int, input().split())

    kM = []
    skM = []
    for _ in range(M):
        sk = list(map(int, input().split()))
        k = sk.pop(0)

        kM.append(k)
        skM.append(sk)

    pM = list(map(int, input().split()))

    k_on_s_ans = None
    for p, k, sk in zip(pM, kM, skM):
        k_on_s = []
        # for i in range(0 + p, k + 1, 2):
        #     k_on_s += itertools.combinations(sk, i)
        for i in range(1, 1 << N):
            i_bits = list(map(lambda x: x + 1, bits2tuple(i)))

            if len(set(sk) & set(i_bits)) % 2 == p:
                k_on_s.append(i_bits)

        if k_on_s_ans is not None:
            k_on_s_ans = [k_on for k_on in k_on_s if k_on in k_on_s_ans]
        else:
            k_on_s_ans = k_on_s

    print(len(k_on_s_ans))


main()
