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

ks = [list(map(int, input().split())) for _ in range(M)]

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



ans = 0

for i in range(1<<N):

    flag = True

    for j in range(M):

        s = ks[j][1:]

        count = 0

        for v in s:

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

                count += 1

        if count % 2 != p[j]:

            flag = False

    

    if flag:

        ans += 1



print(ans)

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



s = []

for i in range(m):

    s.append(list(map(int, input().split()))[1:])

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



ans = 0

for i in range(1<<n):

    isOn = []

    for j in range(n):

        if i & (1<<j):

            isOn.append(j+1)



    flag = True

    for j in range(m):

        count = 0

        for v in s[j]:

            if v in isOn:

                count += 1

        if count % 2 != p[j]:

            flag = False

    if flag:

        ans += 1



print(ans)

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

n, m = list(map(int, input().split()))
s = []
for i in range(m):
    s.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
    isOn = []
    for j in range(n):
        if i & (1 << j):
            isOn.append(j + 1)
    flag = True
    for j in range(m):
        count = 0
        for v in s[j]:
            if v in isOn:
                count += 1
        if count % 2 != p[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

-N, M = list(map(int, input().split())) -ks = [list(map(int, input().split())) for _ in range(M)] +n, m = list(map(int, input().split())) +s = [] +for i in range(m): +    s.append(list(map(int, input().split()))[1:]) -for i in range(1 << N): +for i in range(1 << n): +    isOn = [] +    for j in range(n): +        if i & (1 << j): +            isOn.append(j + 1) -    for j in range(M): -        s = ks[j][1:] +    for j in range(m): -        for v in s: -            if i & (1 << (v - 1)): +        for v in s[j]: +            if v in isOn: