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

s = []

for i in range(M):

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

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



ans = 0

for i in range(2**N):

    Flg = True

    for j in range(M):

        cnt = 0

        for m in range(1, len(s[j])):

            for k in range(N):

                if((i>>k)&1 and s[j][m]-1 == k):

                    cnt += 1

        if(cnt%2 != p[j]):

            Flg = False

    if(Flg):

        ans += 1        

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

s = []

for i in range(M):

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

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



ans = 0

for i in range(2**N):

    Flg = True

    for j in range(M):

        cnt = 0

        for k in range(1, s[j][0]+1):

            if((i>>(s[j][k]-1))&1):

                cnt += 1

        if(cnt%2 != p[j]):

            Flg = False

    if(Flg):

        ans += 1        

print(ans)   
N, M = list(map(int, input().split()))
s = []
for i in range(M):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    Flg = True
    for j in range(M):
        cnt = 0
        for m in range(1, len(s[j])):
            for k in range(N):
                if (i >> k) & 1 and s[j][m] - 1 == k:
                    cnt += 1
        if cnt % 2 != p[j]:
            Flg = False
    if Flg:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
s = []
for i in range(M):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    Flg = True
    for j in range(M):
        cnt = 0
        for k in range(1, s[j][0] + 1):
            if (i >> (s[j][k] - 1)) & 1:
                cnt += 1
        if cnt % 2 != p[j]:
            Flg = False
    if Flg:
        ans += 1
print(ans)

-        for m in range(1, len(s[j])): -            for k in range(N): -                if (i >> k) & 1 and s[j][m] - 1 == k: -                    cnt += 1 +        for k in range(1, s[j][0] + 1): +            if (i >> (s[j][k] - 1)) & 1: +                cnt += 1