import sys
from operator import itemgetter
input=sys.stdin.readline

N,M = map(int,input().split())
ks=[0]*M
for i in range(M):
  ks[i] = list(map(int,input().split()))
ps = list(map(int,input().split()))

X = 2**N
pf = -1
for p in ps:
  if X > 2:
    X//=2
  else:
    if pf != p:
      print(0)
      exit()
  pf = p
print(X)