"""

n,m<=10

"""



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

s = []



for i in range(m):

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

    s.append(sij[1:])



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



ans = 0



for i in range(2**n):

    flag = True

    for k in range(m):

        tst = 0

        for sm in s[k]:

            tst ^= i>>(sm-1)&1

        if tst^p[k]:###

            flag = False

            break

    if flag:

        ans += 1



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

sw = [0 for _ in range(m)]#でんきゅがつながってるスイッチ

for i in range(m):

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

    s = [si-1 for si in s[1:]]

    bt = 0

    for sj in s:#電球

        bt += 1<<sj

    sw[i] = bt

    

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



#スイッチ

bit = 1<<n

ans = 0

for i in range(bit):#スイッチつけ方

    flag = True

    for j in range(m):#電球

        cnt = 0

        for k in range(n):#スイッチチェック

            cnt += (i&sw[j])>>k

        if cnt%2!=p[j]:

            flag = False

    if flag:

        ans += 1

print(ans)

        
"""
n,m<=10
"""
n, m = list(map(int, input().split()))
s = []
for i in range(m):
    sij = list(map(int, input().split()))
    s.append(sij[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    flag = True
    for k in range(m):
        tst = 0
        for sm in s[k]:
            tst ^= i >> (sm - 1) & 1
        if tst ^ p[k]:  ###
            flag = False
            break
    if flag:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
sw = [0 for _ in range(m)]  # でんきゅがつながってるスイッチ
for i in range(m):
    s = list(map(int, input().split()))
    s = [si - 1 for si in s[1:]]
    bt = 0
    for sj in s:  # 電球
        bt += 1 << sj
    sw[i] = bt
p = list(map(int, input().split()))
# スイッチ
bit = 1 << n
ans = 0
for i in range(bit):  # スイッチつけ方
    flag = True
    for j in range(m):  # 電球
        cnt = 0
        for k in range(n):  # スイッチチェック
            cnt += (i & sw[j]) >> k
        if cnt % 2 != p[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

-""" -n,m<=10 -""" -s = [] +sw = [0 for _ in range(m)]  # でんきゅがつながってるスイッチ -    sij = list(map(int, input().split())) -    s.append(sij[1:]) +    s = list(map(int, input().split())) +    s = [si - 1 for si in s[1:]] +    bt = 0 +    for sj in s:  # 電球 +        bt += 1 << sj +    sw[i] = bt +# スイッチ +bit = 1 << n -for i in range(2**n): +for i in range(bit):  # スイッチつけ方 -    for k in range(m): -        tst = 0 -        for sm in s[k]: -            tst ^= i >> (sm - 1) & 1 -        if tst ^ p[k]:  ### +    for j in range(m):  # 電球 +        cnt = 0 +        for k in range(n):  # スイッチチェック +            cnt += (i & sw[j]) >> k +        if cnt % 2 != p[j]: -            break