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

s=[]

k=[]

for i in range(m):

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

    k.append(ss[0])

    s.append(ss[1:])

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





def cntbin(num):

    bin_num = bin(num)[2:]

    count = 0

    for i in bin_num:

            count += int(i)

    return count



ans=0



for bit in range(2**n):

    ok=True

    for mm in range(m):

        on=0

        for i in s[mm]:

            if bit & 2**(i-1)!=0:

                on+=1

        if on%2==p[mm]:

            pass

        else:

            ok=False



    if ok:ans+=1

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

k=[]

s=[]



def cntbin(num):

    bin_num = bin(num)[2:]

    count = 0

    for i in bin_num:

            count += int(i)

    return count



for i in range(m):

    kk,*ss=list(map(int,input().split()))

    k.append(kk)

    s.append(ss)



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



ans=0

for i in range(2**n):

    ok=True

    for mm in range(m):

        if not ok:break

        mask=0

        for ss in s[mm]:

            mask+=1 << ss-1

        on=cntbin(i&mask)

        if p[mm]!=on%2:

            ok=False



    if ok:ans+=1



print(ans)
n, m = list(map(int, input().split()))
s = []
k = []
for i in range(m):
    ss = list(map(int, input().split()))
    k.append(ss[0])
    s.append(ss[1:])
p = list(map(int, input().split()))


def cntbin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
        count += int(i)
    return count


ans = 0
for bit in range(2**n):
    ok = True
    for mm in range(m):
        on = 0
        for i in s[mm]:
            if bit & 2 ** (i - 1) != 0:
                on += 1
        if on % 2 == p[mm]:
            pass
        else:
            ok = False
    if ok:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
k = []
s = []


def cntbin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
        count += int(i)
    return count


for i in range(m):
    kk, *ss = list(map(int, input().split()))
    k.append(kk)
    s.append(ss)
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    ok = True
    for mm in range(m):
        if not ok:
            break
        mask = 0
        for ss in s[mm]:
            mask += 1 << ss - 1
        on = cntbin(i & mask)
        if p[mm] != on % 2:
            ok = False
    if ok:
        ans += 1
print(ans)

+k = [] -k = [] -for i in range(m): -    ss = list(map(int, input().split())) -    k.append(ss[0]) -    s.append(ss[1:]) -p = list(map(int, input().split())) +for i in range(m): +    kk, *ss = list(map(int, input().split())) +    k.append(kk) +    s.append(ss) +p = list(map(int, input().split())) -for bit in range(2**n): +for i in range(2**n): -        on = 0 -        for i in s[mm]: -            if bit & 2 ** (i - 1) != 0: -                on += 1 -        if on % 2 == p[mm]: -            pass -        else: +        if not ok: +            break +        mask = 0 +        for ss in s[mm]: +            mask += 1 << ss - 1 +        on = cntbin(i & mask) +        if p[mm] != on % 2: