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

K = []

S = []

for _ in range(M):

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

    k = KS.pop(0)

    K.append(k)

    S.append(KS)

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



cnt = 2 ** N

ans = 0



for i in range(cnt):

    flg = 1

    for j in range(M):

        s = S[j]

        sum_s = 0

        for x in s:

            sum_s += 2 ** (x - 1)

        calc = sum_s & i

        sum_str = bin(calc)

        div = sum_str.count('1') % 2

        if P[j] == div:

            continue

        else:

            flg = 0

            break

    if flg == 1:

        ans += 1

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

K = []

S = []

for _ in range(M):

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

    k = KS.pop(0)

    K.append(k)

    S.append(KS)

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



cnt = 2 ** N

ans = 0



sum = [0] * M



for j in range(M):

    for x in S[j]:

        sum[j] += 2 ** (x - 1)



for i in range(cnt):

    flg = 1

    for j in range(M):

        calc = sum[j] & i

        sum_str = bin(calc)

        div = sum_str.count('1') % 2

        if P[j] == div:

            continue

        else:

            flg = 0

            break

    if flg == 1:

        ans += 1

print(ans)
N, M = list(map(int, input().split()))
K = []
S = []
for _ in range(M):
    KS = list(map(int, input().split()))
    k = KS.pop(0)
    K.append(k)
    S.append(KS)
P = list(map(int, input().split()))
cnt = 2**N
ans = 0
for i in range(cnt):
    flg = 1
    for j in range(M):
        s = S[j]
        sum_s = 0
        for x in s:
            sum_s += 2 ** (x - 1)
        calc = sum_s & i
        sum_str = bin(calc)
        div = sum_str.count("1") % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
K = []
S = []
for _ in range(M):
    KS = list(map(int, input().split()))
    k = KS.pop(0)
    K.append(k)
    S.append(KS)
P = list(map(int, input().split()))
cnt = 2**N
ans = 0
sum = [0] * M
for j in range(M):
    for x in S[j]:
        sum[j] += 2 ** (x - 1)
for i in range(cnt):
    flg = 1
    for j in range(M):
        calc = sum[j] & i
        sum_str = bin(calc)
        div = sum_str.count("1") % 2
        if P[j] == div:
            continue
        else:
            flg = 0
            break
    if flg == 1:
        ans += 1
print(ans)

+sum = [0] * M +for j in range(M): +    for x in S[j]: +        sum[j] += 2 ** (x - 1) -        s = S[j] -        sum_s = 0 -        for x in s: -            sum_s += 2 ** (x - 1) -        calc = sum_s & i +        calc = sum[j] & i