# coding: utf-8

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

K, S = [], []

for i in range(M):

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

    K.append(tmp[0])

    S.append(tmp[1:])

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



ans = 0

for bit in range(2**N):

    lamp = 0

    switch = [0] * N

    # インデックスに対応したランプがついてる(1, 0)ように変換

    for j in range(N):

        if (bit >> j) & 1 == 1:

            switch[j] = 1

    # 各電球ごとに確認

    for i in range(M):

        cnt = 0

        for k in range(N):

            if k+1 in S[i] and switch[k] == 1:

                cnt += 1

        # print("cnt", cnt)

        if cnt % 2 == P[i]:

            lamp += 1

    if lamp == M:

        ans += 1

print(ans)
# coding: utf-8

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

S = []

for i in range(M):

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

    S.append(tmp[1:])

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

ans = 0

# print(S)

for bit in range(2**N):

    l = []

    for j in range(N):

        if bit >> j & 1 == 1:

            l.append(1)

        else:

            l.append(0)

    flag = True

    for j in range(M):

        t = S[j]

        cnt = 0

        for k in range(len(S[j])):

            if l[t[k]-1] == 1:

                cnt += 1

            # else:

            #     flag = False

        if cnt % 2 != P[j]:

            flag = False

    if flag:

        # print(bin(bit))

        ans += 1

print(ans)
# coding: utf-8
N, M = list(map(int, input().split()))
K, S = [], []
for i in range(M):
    tmp = list(map(int, input().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(2**N):
    lamp = 0
    switch = [0] * N
    # インデックスに対応したランプがついてる(1, 0)ように変換
    for j in range(N):
        if (bit >> j) & 1 == 1:
            switch[j] = 1
    # 各電球ごとに確認
    for i in range(M):
        cnt = 0
        for k in range(N):
            if k + 1 in S[i] and switch[k] == 1:
                cnt += 1
        # print("cnt", cnt)
        if cnt % 2 == P[i]:
            lamp += 1
    if lamp == M:
        ans += 1
print(ans)

# coding: utf-8
N, M = list(map(int, input().split()))
S = []
for i in range(M):
    tmp = list(map(int, input().split()))
    S.append(tmp[1:])
P = list(map(int, input().split()))
ans = 0
# print(S)
for bit in range(2**N):
    l = []
    for j in range(N):
        if bit >> j & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    flag = True
    for j in range(M):
        t = S[j]
        cnt = 0
        for k in range(len(S[j])):
            if l[t[k] - 1] == 1:
                cnt += 1
            # else:
            #     flag = False
        if cnt % 2 != P[j]:
            flag = False
    if flag:
        # print(bin(bit))
        ans += 1
print(ans)

-K, S = [], [] +S = [] -    K.append(tmp[0]) +# print(S) -    lamp = 0 -    switch = [0] * N -    # インデックスに対応したランプがついてる(1, 0)ように変換 +    l = [] -        if (bit >> j) & 1 == 1: -            switch[j] = 1 -    # 各電球ごとに確認 -    for i in range(M): +        if bit >> j & 1 == 1: +            l.append(1) +        else: +            l.append(0) +    flag = True +    for j in range(M): +        t = S[j] -        for k in range(N): -            if k + 1 in S[i] and switch[k] == 1: +        for k in range(len(S[j])): +            if l[t[k] - 1] == 1: -        # print("cnt", cnt) -        if cnt % 2 == P[i]: -            lamp += 1 -    if lamp == M: +            # else: +            #     flag = False +        if cnt % 2 != P[j]: +            flag = False +    if flag: +        # print(bin(bit))