N, M = map(int, input().split())
K, S = [], []
for _ in range(M):
	k, *s = map(int, input().split())
	K.append(k)
	S.append(list(map(lambda x: x-1, s)))
p = list(map(int, input().split()))
res = 0
for i in range(1<<N):
	flag = True
	for j in range(M):
		cnt = 0
		for k in S[j]:
			if (i >> k) & 1:
				cnt += 1
				print(i, k, cnt)

		if cnt%2 != p[j]:
			flag = False
			
	if flag: res += 1
print(res)
