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
kssf=-1
for kss,p in zip(ks,ps):
  if X > 2:
    if (pf == p) and (kss==kssf):
      pass
    else:
      X//=2
  else:
    if pf != p:
      print(0)
      exit()
  pf = p
  kssf=kss
print(X)