from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()
    N, M = map(int, input().split())
    KS = [list(map(int, input().split())) for _ in [0] * M]
    P = tuple(map(int, input().split()))

    sw = defaultdict(list)
    for i, ks in enumerate(KS, start=1):
        for s in ks[1:]:
            sw[s].append(i)

    light = [False] * (M + 1)
    ans = 0
    for mask in range(1 << N):
        li = light[:]
        for i in range(N):
            if mask & 1 << i:
                for j in sw[i+1]:
                    li[j] = (li[j] + 1) % 2
        if P == tuple(li[:0:-1]):
            ans += 1
    print(ans)


main()
