import numpy as np
N, M = map(int, input().split())
s = []
for i in range(M):
    t = []
    ks = list(map(int, input().split()))[1:]
    for j in range(N):
        if j+1 in ks:
            t += [1]
        else:
            t += [0]
    s.append(t)
p = list(map(int, input().split()))
A = np.array(s)
for i in range(M):
    s[i] += [p[i]]
Ab = np.array(s)
rank_A = np.linalg.matrix_rank(A)
rank_Ab = np.linalg.matrix_rank(Ab)
if rank_A == rank_Ab:
    print(2 ** (N - rank_A))
else:
    print(0)
