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

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

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



def count_on_switch(switch_array: list, on: set):

    return sum([int(sw in on) for sw in switch_array])



ans = 0

# print("---")

for i in range(2**N):

    on = set()

    for j in range(N):

        if ((i >> j) & 1):

             on.add(j+1)

    temp = 0

    for _ in range(M):

        cou_on = count_on_switch(slist[_], on)

        # print(i, cou_on)

        if cou_on % 2 != plist[_]:

            break

    else:

        ans += 1

print(ans)

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

s_setlist = []

for i in range(M):

    k, *s = list(map(int, input().split()))

    s_setlist.append(set(s))

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



ans = 0

for i in range(2**N):

    on = set()

    for j in range(N):

        if ((i >> j) & 1):

            on.add(j+1)

    light_list = [len(on&s_setlist[k])%2==plist[k] for k in range(M)]

    if all(light_list):

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
slist = [list(map(int, input().split()))[1:] for _ in range(M)]
plist = list(map(int, input().split()))


def count_on_switch(switch_array: list, on: set):
    return sum([int(sw in on) for sw in switch_array])


ans = 0
# print("---")
for i in range(2**N):
    on = set()
    for j in range(N):
        if (i >> j) & 1:
            on.add(j + 1)
    temp = 0
    for _ in range(M):
        cou_on = count_on_switch(slist[_], on)
        # print(i, cou_on)
        if cou_on % 2 != plist[_]:
            break
    else:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
s_setlist = []
for i in range(M):
    k, *s = list(map(int, input().split()))
    s_setlist.append(set(s))
plist = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    on = set()
    for j in range(N):
        if (i >> j) & 1:
            on.add(j + 1)
    light_list = [len(on & s_setlist[k]) % 2 == plist[k] for k in range(M)]
    if all(light_list):
        ans += 1
print(ans)

-slist = [list(map(int, input().split()))[1:] for _ in range(M)] +s_setlist = [] +for i in range(M): +    k, *s = list(map(int, input().split())) +    s_setlist.append(set(s)) - - -def count_on_switch(switch_array: list, on: set): -    return sum([int(sw in on) for sw in switch_array]) - - -    temp = 0 -    for _ in range(M): -        cou_on = count_on_switch(slist[_], on) -        # print(i, cou_on) -        if cou_on % 2 != plist[_]: -            break -    else: +    light_list = [len(on & s_setlist[k]) % 2 == plist[k] for k in range(M)] +    if all(light_list):