N,M = map(int,input().split())
KS = [[int(x) for x in input().split()] for _ in range(M)]
P = list(map(int,input().split()))

bit = (2 << N) - 1
cnt = 0

for i in range(bit):
  switch = [0] * N
  for j in range(N):
    isOn = (i >> j) & 1
    switch[j] = isOn

  ok = True
  for k in range(M):
    t = KS[k][1:]
    for l in t:
      if not isOn:
        ok = False
        break
    if not ok:
      break

  if ok:
    cnt += 1
    
print(cnt)