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

ks = [[int(i) for i in input().split()] for j in range(M)]

p = [int(i) for i in input().split()]



ans = 0

for i in range((1 << N)):

    count = 0

    for j in range(M):

        k = ks[j][0]

        on = 0

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

            if i & (1 << (s-1)):

                on += 1

        

        if on % 2 == p[j]:

            count += 1



    if count == M:

        ans += 1



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

switches = [[int(i) for i in input().split()] for i in range(M)]

P = [int(i) for i in input().split()]



ans = 0

for pattern in range(1 << N):

    for i in range(M):

        k = switches[i][0]

        switch = switches[i][1:]

        count= 0

        for j in range(k):

            if 1 & (pattern >> switch[j]-1):

                count += 1

        

        if count % 2 != P[i]:

            break

    else: ans += 1



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

N, M = list(map(int, input().split()))
switches = [[int(i) for i in input().split()] for i in range(M)]
P = [int(i) for i in input().split()]
ans = 0
for pattern in range(1 << N):
    for i in range(M):
        k = switches[i][0]
        switch = switches[i][1:]
        count = 0
        for j in range(k):
            if 1 & (pattern >> switch[j] - 1):
                count += 1
        if count % 2 != P[i]:
            break
    else:
        ans += 1
print(ans)

-ks = [[int(i) for i in input().split()] for j in range(M)] -p = [int(i) for i in input().split()] +switches = [[int(i) for i in input().split()] for i in range(M)] +P = [int(i) for i in input().split()] -for i in range((1 << N)): -    count = 0 -    for j in range(M): -        k = ks[j][0] -        on = 0 -        for s in ks[j][1:]: -            if i & (1 << (s - 1)): -                on += 1 -        if on % 2 == p[j]: -            count += 1 -    if count == M: +for pattern in range(1 << N): +    for i in range(M): +        k = switches[i][0] +        switch = switches[i][1:] +        count = 0 +        for j in range(k): +            if 1 & (pattern >> switch[j] - 1): +                count += 1 +        if count % 2 != P[i]: +            break +    else: