[input_n, input_m] = list(map(int, input().split()))



input_ks = [list(map(int, input().split())) for i in range(input_m)]

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



switch_list = [[bool(i & 2 ** j) for j in range(input_n)]

               for i in range(2 ** input_n)]



count = 0

for switch in switch_list:

    switchPattern = []

    for m in range(input_m):

        switchPattern.append(sum(switch[l - 1] for l in input_ks[m][1:]) %2 == input_p[m])

    if (all(switchPattern)):

        count += 1

print(count)
[input_n, input_m] = list(map(int, input().split()))



input_ks = [list(map(int, input().split())) for i in range(input_m)]

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



switch_list = [[bool(i & 2 ** j) for j in range(input_n)]

               for i in range(2 ** input_n)]



count = len(switch_list)

for switch in switch_list:

    for m in range(input_m):

        if ((sum(switch[l - 1] for l in input_ks[m][1:])-input_p[m]) % 2):

            count -= 1

            break

print(count)

[input_n, input_m] = list(map(int, input().split()))
input_ks = [list(map(int, input().split())) for i in range(input_m)]
input_p = list(map(int, input().split()))
switch_list = [[bool(i & 2**j) for j in range(input_n)] for i in range(2**input_n)]
count = 0
for switch in switch_list:
    switchPattern = []
    for m in range(input_m):
        switchPattern.append(
            sum(switch[l - 1] for l in input_ks[m][1:]) % 2 == input_p[m]
        )
    if all(switchPattern):
        count += 1
print(count)

[input_n, input_m] = list(map(int, input().split()))
input_ks = [list(map(int, input().split())) for i in range(input_m)]
input_p = list(map(int, input().split()))
switch_list = [[bool(i & 2**j) for j in range(input_n)] for i in range(2**input_n)]
count = len(switch_list)
for switch in switch_list:
    for m in range(input_m):
        if (sum(switch[l - 1] for l in input_ks[m][1:]) - input_p[m]) % 2:
            count -= 1
            break
print(count)

-count = 0 +count = len(switch_list) -    switchPattern = [] -        switchPattern.append( -            sum(switch[l - 1] for l in input_ks[m][1:]) % 2 == input_p[m] -        ) -    if all(switchPattern): -        count += 1 +        if (sum(switch[l - 1] for l in input_ks[m][1:]) - input_p[m]) % 2: +            count -= 1 +            break