N, M = input().split()
K = []
P = []
adjacent = [[0] for i in range(M)]
for i in range(M):
  A = list(input())
  K[i] = A[0]
  adjacent[i] = A[1:]
P = list(input())
X = 0
a = [[0] for i in range(M)]
for i in range(2**N):
  b = []
  for j in range(N):
    if i%2 == 1:
      b.append(j)
    i = i//2
  for j in range(M):
    if len(set(b)&set(adjacent[j]))%2 == P[j]:
      a[j] = 1
  if sum(a) == M:
    X += 1
print(X)
    