from functools import reduce
N,M = [int(x) for x in input().split()]
st = [0]*M
st2 = [0]*N
for i in range(M):
  a = list(map(int,input().split()))
  for j in range(a[0]):
    st[i] += 10**(a[j+1]-1)
for i in range(N):
  for j in range(M):
    st2[i] += (st[j] & 1)*(10**(M - (j+1)))
    st[j] = st[j] // 10
b = map(int,input().split())
p = reduce( lambda c,d:10*c+d, b)
h = 0
cnt = 0
for i in range(2**N):
  for j in range(M):
    if (i >> j) & 1:
      h = h ^ st2[j]
  if p == h:
    cnt += 1
  h = 0
print(cnt)