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

S = []

for _ in range(M):

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

    bit = 0

    for i in arr[1:]:

        # print(i)

        bit = bit | (1 << (i - 1))

    # print('bit', bit, bin(bit))

    S.append(bit)

    # S.append(arr[1:])

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

# print('S')

# print(S)

# print('P', P)

ans = 0

for bit in range(1 << N):

    cnt = 0

    for i in range(M):

        # print('S[i], bit', bin(S[i]), bin(bit))

        p = S[i] & bit

        # print('p', bin(p))

        on = 0

        for j in range(N):

            # print('judge', 1 << j, p & (1 << j))

            if p & (1 << j):

                on += 1

            # if p & (1 << j):

            #     on += 1

        # print('P[i], i, on', P[i], i, on)

        # print('on', on)

        if (on % 2) == P[i]:

            cnt += 1

    if cnt == M:

        ans += 1

print(ans)

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

S = []

for _ in range(M):

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

    bit = 0

    for i in arr[1:]:

        bit = bit | (1 << (i - 1))

    S.append(bit)

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



ans = 0

for bit in range(1 << N):

    for i in range(M):

        p = S[i] & bit

        on = 0

        for j in range(N):

            if p & (1 << j):

                on += 1

        if (on % 2) != P[i]:

            break

    else:

        ans += 1

print(ans)

N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    arr = list(map(int, input().split()))
    bit = 0
    for i in arr[1:]:
        # print(i)
        bit = bit | (1 << (i - 1))
    # print('bit', bit, bin(bit))
    S.append(bit)
    # S.append(arr[1:])
P = list(map(int, input().split()))
# print('S')
# print(S)
# print('P', P)
ans = 0
for bit in range(1 << N):
    cnt = 0
    for i in range(M):
        # print('S[i], bit', bin(S[i]), bin(bit))
        p = S[i] & bit
        # print('p', bin(p))
        on = 0
        for j in range(N):
            # print('judge', 1 << j, p & (1 << j))
            if p & (1 << j):
                on += 1
            # if p & (1 << j):
            #     on += 1
        # print('P[i], i, on', P[i], i, on)
        # print('on', on)
        if (on % 2) == P[i]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    arr = list(map(int, input().split()))
    bit = 0
    for i in arr[1:]:
        bit = bit | (1 << (i - 1))
    S.append(bit)
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for i in range(M):
        p = S[i] & bit
        on = 0
        for j in range(N):
            if p & (1 << j):
                on += 1
        if (on % 2) != P[i]:
            break
    else:
        ans += 1
print(ans)

-        # print(i) -    # print('bit', bit, bin(bit)) -    # S.append(arr[1:]) -# print('S') -# print(S) -# print('P', P) -    cnt = 0 -        # print('S[i], bit', bin(S[i]), bin(bit)) -        # print('p', bin(p)) -            # print('judge', 1 << j, p & (1 << j)) -            # if p & (1 << j): -            #     on += 1 -        # print('P[i], i, on', P[i], i, on) -        # print('on', on) -        if (on % 2) == P[i]: -            cnt += 1 -    if cnt == M: +        if (on % 2) != P[i]: +            break +    else: