

n, m = list(map(int, input().split(' ')))

k = []

s = []

for i in range(m):

    a = list(map(int, input().split(' ')))

    k.append(a[0])

    s.append(a[1:])

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

ans = 0

for i in range(2**n):

    ri_cnt = 0

    for j in range(m):

        sw_cnt = 0

        for l in range(k[j]):

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

                sw_cnt += 1

        if sw_cnt % 2 == p[j]:

            ri_cnt += 1

    if ri_cnt == m:

        ans += 1

print(ans)

n, m = list(map(int, input().split(' ')))

K = []

S = []

for i in range(m):

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

    K.append(l[0])

    S.append(l[1:])

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

ans = 0

for i in range(2**n):

    light = 0

    for j in range(m):

        sw = 0

        for s in S[j]:

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

                sw += 1

        if sw%2 == p[j]:

            light+=1

    if light == m:

        ans += 1

print(ans)
n, m = list(map(int, input().split(" ")))
k = []
s = []
for i in range(m):
    a = list(map(int, input().split(" ")))
    k.append(a[0])
    s.append(a[1:])
p = list(map(int, input().split(" ")))
ans = 0
for i in range(2**n):
    ri_cnt = 0
    for j in range(m):
        sw_cnt = 0
        for l in range(k[j]):
            if (i >> (s[j][l] - 1)) & 1:
                sw_cnt += 1
        if sw_cnt % 2 == p[j]:
            ri_cnt += 1
    if ri_cnt == m:
        ans += 1
print(ans)

n, m = list(map(int, input().split(" ")))
K = []
S = []
for i in range(m):
    l = list(map(int, input().split(" ")))
    K.append(l[0])
    S.append(l[1:])
p = list(map(int, input().split(" ")))
ans = 0
for i in range(2**n):
    light = 0
    for j in range(m):
        sw = 0
        for s in S[j]:
            if (i >> (s - 1)) & 1:
                sw += 1
        if sw % 2 == p[j]:
            light += 1
    if light == m:
        ans += 1
print(ans)

-k = [] -s = [] +K = [] +S = [] -    a = list(map(int, input().split(" "))) -    k.append(a[0]) -    s.append(a[1:]) +    l = list(map(int, input().split(" "))) +    K.append(l[0]) +    S.append(l[1:]) -    ri_cnt = 0 +    light = 0 -        sw_cnt = 0 -        for l in range(k[j]): -            if (i >> (s[j][l] - 1)) & 1: -                sw_cnt += 1 -        if sw_cnt % 2 == p[j]: -            ri_cnt += 1 -    if ri_cnt == m: +        sw = 0 +        for s in S[j]: +            if (i >> (s - 1)) & 1: +                sw += 1 +        if sw % 2 == p[j]: +            light += 1 +    if light == m: