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

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

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



ans = 0

for i in range(2**N):

    cnt = 0

    for j in range(M):

        count = 0

        for k in ks[j][1::]:

            if (i >> k-1)&1 == 1:

                count += 1

        if count%2 == p[j]:

            cnt += 1

    if cnt == M:

        ans += 1

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

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

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



def check(ar):

    cnt = 0

    for j in range(M):

        count = 0

        for k in ks[j][1::]:

            if ar[k-1] == 1:

                count += 1

        if count%2 == p[j]:

            cnt += 1

    return (cnt == M)





def dfs(n, ar):

    if n == 0:

        if check(ar):

            return 1

        else:

            return 0

    else:

        return dfs(n-1, ar+[0]) + dfs(n-1, ar+[1])

arr = []

ans = dfs(N, arr)

print(ans)

N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k - 1) & 1 == 1:
                count += 1
        if count % 2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))


def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if ar[k - 1] == 1:
                count += 1
        if count % 2 == p[j]:
            cnt += 1
    return cnt == M


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n - 1, ar + [0]) + dfs(n - 1, ar + [1])


arr = []
ans = dfs(N, arr)
print(ans)

-ans = 0 -for i in range(2**N): + + +def check(ar): -            if (i >> k - 1) & 1 == 1: +            if ar[k - 1] == 1: -    if cnt == M: -        ans += 1 +    return cnt == M + + +def dfs(n, ar): +    if n == 0: +        if check(ar): +            return 1 +        else: +            return 0 +    else: +        return dfs(n - 1, ar + [0]) + dfs(n - 1, ar + [1]) + + +arr = [] +ans = dfs(N, arr)