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

switches_bulbs_connection = {}



for i in range(M):

    switches_bulbs_connection[i] = list(map(int, input().split()))[1:]

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

count = 0

flag = 0



for i in range(2 ** N):  # スイッチのon/offについてビット全探索

    switch_on_off = [0] * N

    bulb_stat = [0] * M

    for j in range(N):

        if (i >> j) & 1:

            switch_on_off[j] += 1  # 各スイッチがonかoffか

    for k in range(M):  # 電球kについて調べる

        tmp = switches_bulbs_connection[k]

        for switch in tmp:

            if switch_on_off[switch-1]:

                bulb_stat[k] += 1

    for l in range(M):

        if bulb_stat[l] % 2 == p[l]:

            flag += 1

    if flag == M:

        count += 1

    flag = 0



print(count)

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

bulb = []

count = 0



for _ in range(M):

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

    bulb.append(tmp[1:])



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



for i in range(2 ** N):

    switch = []

    for j in range(N):  # スイッチの押し方を全探索

        if (i >> j) & 1:

            switch.append(j+1)

    bulb_count = M

    for k in range(M):  # M個の電球それぞれがついているか判定

        tmp = bulb[k]  # tmpは電球k につながっているスイッチ

        switch_count = 0

        for num in tmp:  # 電球kのスイッチについて判定

            if num in switch:

                switch_count += 1

        if switch_count % 2 == P[k]:

            bulb_count -= 1

    if bulb_count == 0:

        count += 1



print(count)

N, M = list(map(int, input().split()))
switches_bulbs_connection = {}
for i in range(M):
    switches_bulbs_connection[i] = list(map(int, input().split()))[1:]
p = list(map(int, input().split()))
count = 0
flag = 0
for i in range(2**N):  # スイッチのon/offについてビット全探索
    switch_on_off = [0] * N
    bulb_stat = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            switch_on_off[j] += 1  # 各スイッチがonかoffか
    for k in range(M):  # 電球kについて調べる
        tmp = switches_bulbs_connection[k]
        for switch in tmp:
            if switch_on_off[switch - 1]:
                bulb_stat[k] += 1
    for l in range(M):
        if bulb_stat[l] % 2 == p[l]:
            flag += 1
    if flag == M:
        count += 1
    flag = 0
print(count)

N, M = list(map(int, input().split()))
bulb = []
count = 0
for _ in range(M):
    tmp = list(map(int, input().split()))
    bulb.append(tmp[1:])
P = list(map(int, input().split()))
for i in range(2**N):
    switch = []
    for j in range(N):  # スイッチの押し方を全探索
        if (i >> j) & 1:
            switch.append(j + 1)
    bulb_count = M
    for k in range(M):  # M個の電球それぞれがついているか判定
        tmp = bulb[k]  # tmpは電球k につながっているスイッチ
        switch_count = 0
        for num in tmp:  # 電球kのスイッチについて判定
            if num in switch:
                switch_count += 1
        if switch_count % 2 == P[k]:
            bulb_count -= 1
    if bulb_count == 0:
        count += 1
print(count)

-switches_bulbs_connection = {} -for i in range(M): -    switches_bulbs_connection[i] = list(map(int, input().split()))[1:] -p = list(map(int, input().split())) +bulb = [] -flag = 0 -for i in range(2**N):  # スイッチのon/offについてビット全探索 -    switch_on_off = [0] * N -    bulb_stat = [0] * M -    for j in range(N): +for _ in range(M): +    tmp = list(map(int, input().split())) +    bulb.append(tmp[1:]) +P = list(map(int, input().split())) +for i in range(2**N): +    switch = [] +    for j in range(N):  # スイッチの押し方を全探索 -            switch_on_off[j] += 1  # 各スイッチがonかoffか -    for k in range(M):  # 電球kについて調べる -        tmp = switches_bulbs_connection[k] -        for switch in tmp: -            if switch_on_off[switch - 1]: -                bulb_stat[k] += 1 -    for l in range(M): -        if bulb_stat[l] % 2 == p[l]: -            flag += 1 -    if flag == M: +            switch.append(j + 1) +    bulb_count = M +    for k in range(M):  # M個の電球それぞれがついているか判定 +        tmp = bulb[k]  # tmpは電球k につながっているスイッチ +        switch_count = 0 +        for num in tmp:  # 電球kのスイッチについて判定 +            if num in switch: +                switch_count += 1 +        if switch_count % 2 == P[k]: +            bulb_count -= 1 +    if bulb_count == 0: -    flag = 0