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

k = [0]*M

s = [""]*M

for i in range(M):

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

    k[i] = tmp[0]

    s[i] = tmp[1:]



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

ans = 0

for i in range(2**N):

    global_count = 0

    for j in range(M):

        local_count = 0

        for x in s[j]:

            if (i >> (x - 1)) % 2 == 0:

                continue

            else:

                local_count += 1

        if local_count % 2 == p[j]:

            global_count += 1

    if global_count == M:

        ans += 1



print(ans)

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





K = [[0]*N for i in range(M)]





for i in range(M):

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

    for j in tmp[1:]:

        K[i][j-1] = 1

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

ans = 0

for i in range(2**N):

    tmp = [0]*M

    for j in range(N):

        if (i >> j) % 2 == 1:

            for k in range(M):

                tmp[k] += K[k][j]

    for j in range(M):

        if tmp[j] % 2 != p[j]:

            break

        if j == M-1:

            ans += 1





print(ans)

N, M = list(map(int, input().split()))
k = [0] * M
s = [""] * M
for i in range(M):
    tmp = list(map(int, input().split()))
    k[i] = tmp[0]
    s[i] = tmp[1:]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    global_count = 0
    for j in range(M):
        local_count = 0
        for x in s[j]:
            if (i >> (x - 1)) % 2 == 0:
                continue
            else:
                local_count += 1
        if local_count % 2 == p[j]:
            global_count += 1
    if global_count == M:
        ans += 1
print(ans)

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

-k = [0] * M -s = [""] * M +K = [[0] * N for i in range(M)] -    k[i] = tmp[0] -    s[i] = tmp[1:] +    for j in tmp[1:]: +        K[i][j - 1] = 1 -    global_count = 0 +    tmp = [0] * M +    for j in range(N): +        if (i >> j) % 2 == 1: +            for k in range(M): +                tmp[k] += K[k][j] -        local_count = 0 -        for x in s[j]: -            if (i >> (x - 1)) % 2 == 0: -                continue -            else: -                local_count += 1 -        if local_count % 2 == p[j]: -            global_count += 1 -    if global_count == M: -        ans += 1 +        if tmp[j] % 2 != p[j]: +            break +        if j == M - 1: +            ans += 1