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

cnt = 0

K = list()

L = list()

for m in range(M):

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

    k = l.pop(0)

    K.append(k)

    L.append(l)

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

for i in range(1<<N):

    flag = True

    for j in range(M):

        c = 0

        for l in range(K[j]):

            if i & (1<<L[j][l]-1):

                c += 1

        if c % 2 != P[j]:

            flag = False

    if flag:

        cnt += 1

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

K = []

S = []

for m in range(M):

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

    k = l.pop(0)

    K.append(k)

    S.append(l)

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

ans = 0

for n in range(1<<N):

    res = True

    for m in range(M):

        cnt = 0

        for q in range(K[m]):

            if n & (1<<S[m][q]-1):

                cnt += 1

        if cnt % 2 != P[m]:

            res = False

    if res:

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
cnt = 0
K = list()
L = list()
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    L.append(l)
P = list(map(int, input().split()))
for i in range(1 << N):
    flag = True
    for j in range(M):
        c = 0
        for l in range(K[j]):
            if i & (1 << L[j][l] - 1):
                c += 1
        if c % 2 != P[j]:
            flag = False
    if flag:
        cnt += 1
print(cnt)

N, M = list(map(int, input().split()))
K = []
S = []
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    S.append(l)
P = list(map(int, input().split()))
ans = 0
for n in range(1 << N):
    res = True
    for m in range(M):
        cnt = 0
        for q in range(K[m]):
            if n & (1 << S[m][q] - 1):
                cnt += 1
        if cnt % 2 != P[m]:
            res = False
    if res:
        ans += 1
print(ans)

-cnt = 0 -K = list() -L = list() +K = [] +S = [] -    L.append(l) +    S.append(l) -for i in range(1 << N): -    flag = True -    for j in range(M): -        c = 0 -        for l in range(K[j]): -            if i & (1 << L[j][l] - 1): -                c += 1 -        if c % 2 != P[j]: -            flag = False -    if flag: -        cnt += 1 -print(cnt) +ans = 0 +for n in range(1 << N): +    res = True +    for m in range(M): +        cnt = 0 +        for q in range(K[m]): +            if n & (1 << S[m][q] - 1): +                cnt += 1 +        if cnt % 2 != P[m]: +            res = False +    if res: +        ans += 1 +print(ans)