N, M = list(map(int, input().split()))



switch = [list(map(int, input().split())) for _ in range(M)]

B = []

for K, *S in switch:

    b = 0

    for k in range(K):

        b += (1 << (S[k] - 1))

    B.append(b)



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



ans = 0

for i in range(2 ** N):

    on = True

    for j, b in enumerate(B):

        cnt = 0

        state = b & i

        while state > 0:

            cnt += state & 1

            state >>= 1

        on &= (cnt % 2 == P[j])

    ans += on



print(ans)

def cntBit(n):

    cnt = 0

    while n > 0:

        cnt += (n & 1)

        n >>= 1

    return cnt





N, M = list(map(int, input().split()))



switch = [list(map(int, input().split())) for _ in range(M)]

B = []

for K, *S in switch:

    b = 0

    for k in range(K):

        b += (1 << (S[k] - 1))

    B.append(b)

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



ans = 0

for i in range(2 ** N):

    on = True

    B1 = list([x & i for x in B])

    B2 = list(map(cntBit, B1))

    B3 = list([x % 2 for x in B2])



    if B3 == P:

        ans += 1



print(ans)

N, M = list(map(int, input().split()))
switch = [list(map(int, input().split())) for _ in range(M)]
B = []
for K, *S in switch:
    b = 0
    for k in range(K):
        b += 1 << (S[k] - 1)
    B.append(b)
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    on = True
    for j, b in enumerate(B):
        cnt = 0
        state = b & i
        while state > 0:
            cnt += state & 1
            state >>= 1
        on &= cnt % 2 == P[j]
    ans += on
print(ans)

def cntBit(n):
    cnt = 0
    while n > 0:
        cnt += n & 1
        n >>= 1
    return cnt


N, M = list(map(int, input().split()))
switch = [list(map(int, input().split())) for _ in range(M)]
B = []
for K, *S in switch:
    b = 0
    for k in range(K):
        b += 1 << (S[k] - 1)
    B.append(b)
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    on = True
    B1 = list([x & i for x in B])
    B2 = list(map(cntBit, B1))
    B3 = list([x % 2 for x in B2])
    if B3 == P:
        ans += 1
print(ans)

+def cntBit(n): +    cnt = 0 +    while n > 0: +        cnt += n & 1 +        n >>= 1 +    return cnt + + -    for j, b in enumerate(B): -        cnt = 0 -        state = b & i -        while state > 0: -            cnt += state & 1 -            state >>= 1 -        on &= cnt % 2 == P[j] -    ans += on +    B1 = list([x & i for x in B]) +    B2 = list(map(cntBit, B1)) +    B3 = list([x % 2 for x in B2]) +    if B3 == P: +        ans += 1