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

S = []

for _ in range(M):

  s_list = ['0' for _ in range(N)]

  for s in list(map(int, input().split()))[1:]:s_list[s-1] = '1'

  S.append(int(''.join(s_list),2))



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

ans = 0

for i in range(2**N):

  flag = True

  for idx, s in enumerate(S):

    if bin(i&s)[2:].count('1')%2 != P[idx]:

      flag = False

      break

  if flag is True: ans += 1

print(ans)
def is_all_switches_on(on_case):

    for i, s in enumerate(S):

        on_switch_num = 0

        for si in s:

            if on_case[si] == '1':

                on_switch_num += 1



        if on_switch_num % 2 != switches[i]:

            return False

    return True



if __name__ == '__main__':

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

    S = []

    for _ in range(M):

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

        S.append(s)



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



    ans = 0

    for i in range(2 ** N):



        on_case = '0' + bin(i)[2:].zfill(N)

        if is_all_switches_on(on_case):

            ans += 1

    print(ans)
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    s_list = ["0" for _ in range(N)]
    for s in list(map(int, input().split()))[1:]:
        s_list[s - 1] = "1"
    S.append(int("".join(s_list), 2))
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    flag = True
    for idx, s in enumerate(S):
        if bin(i & s)[2:].count("1") % 2 != P[idx]:
            flag = False
            break
    if flag is True:
        ans += 1
print(ans)

def is_all_switches_on(on_case):
    for i, s in enumerate(S):
        on_switch_num = 0
        for si in s:
            if on_case[si] == "1":
                on_switch_num += 1
        if on_switch_num % 2 != switches[i]:
            return False
    return True


if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    S = []
    for _ in range(M):
        k, *s = list(map(int, input().split()))
        S.append(s)
    switches = list(map(int, input().split()))
    ans = 0
    for i in range(2**N):
        on_case = "0" + bin(i)[2:].zfill(N)
        if is_all_switches_on(on_case):
            ans += 1
    print(ans)

-N, M = list(map(int, input().split())) -S = [] -for _ in range(M): -    s_list = ["0" for _ in range(N)] -    for s in list(map(int, input().split()))[1:]: -        s_list[s - 1] = "1" -    S.append(int("".join(s_list), 2)) -P = list(map(int, input().split())) -ans = 0 -for i in range(2**N): -    flag = True -    for idx, s in enumerate(S): -        if bin(i & s)[2:].count("1") % 2 != P[idx]: -            flag = False -            break -    if flag is True: -        ans += 1 -print(ans) +def is_all_switches_on(on_case): +    for i, s in enumerate(S): +        on_switch_num = 0 +        for si in s: +            if on_case[si] == "1": +                on_switch_num += 1 +        if on_switch_num % 2 != switches[i]: +            return False +    return True + + +if __name__ == "__main__": +    N, M = list(map(int, input().split())) +    S = [] +    for _ in range(M): +        k, *s = list(map(int, input().split())) +        S.append(s) +    switches = list(map(int, input().split())) +    ans = 0 +    for i in range(2**N): +        on_case = "0" + bin(i)[2:].zfill(N) +        if is_all_switches_on(on_case): +            ans += 1 +    print(ans)