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

K = []; S = []

for _ in range(M):

    k, *s = list(map(int, input().split()))

    K.append(k); S.append(s)

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



ans = 0

for i in range(2**N):

    flag = 0

    stat = str(bin(i)[2:])

    stat = stat.rjust(N, "0")

    for j in range(M):

        p = 0

        for l in S[j]:

            p += int(stat[l-1])

        if p % 2 != P[j]:

            flag = 1

    if flag == 0:

        ans += 1



print(ans)

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

lightList = []

for _ in range(M):

    lightList.append(list(map(int, input().split())))

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



ans = 0

for i in range(2**N):

    flag = True

    for a in range(M):

        cnt = 0

        for b in lightList[a][1:]:

            if not (i & (1<<b-1)):

                cnt += 1

        if cnt % 2 != P[a]:

            flag = False

    if flag:

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
K = []
S = []
for _ in range(M):
    k, *s = list(map(int, input().split()))
    K.append(k)
    S.append(s)
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    flag = 0
    stat = str(bin(i)[2:])
    stat = stat.rjust(N, "0")
    for j in range(M):
        p = 0
        for l in S[j]:
            p += int(stat[l - 1])
        if p % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
lightList = []
for _ in range(M):
    lightList.append(list(map(int, input().split())))
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    flag = True
    for a in range(M):
        cnt = 0
        for b in lightList[a][1:]:
            if not (i & (1 << b - 1)):
                cnt += 1
        if cnt % 2 != P[a]:
            flag = False
    if flag:
        ans += 1
print(ans)

-K = [] -S = [] +lightList = [] -    k, *s = list(map(int, input().split())) -    K.append(k) -    S.append(s) +    lightList.append(list(map(int, input().split()))) -    flag = 0 -    stat = str(bin(i)[2:]) -    stat = stat.rjust(N, "0") -    for j in range(M): -        p = 0 -        for l in S[j]: -            p += int(stat[l - 1]) -        if p % 2 != P[j]: -            flag = 1 -    if flag == 0: +    flag = True +    for a in range(M): +        cnt = 0 +        for b in lightList[a][1:]: +            if not (i & (1 << b - 1)): +                cnt += 1 +        if cnt % 2 != P[a]: +            flag = False +    if flag: