import Data.Array
import Control.Monad

gen_all_pat::Int->[Array Int Bool]
gen_all_pat n = let rec_gen i = if i == 0 then [[]] else concat [ [(False:ls),(True:ls)] | ls <- rec_gen (i-1)] in
                (map (listArray (1,n))) (rec_gen n)

gen_checker::(Int,[Int]) -> Array Int Bool -> Bool
gen_checker (p,ls) ar = (mod (length (filter id [ar!i|i<-ls])) 2) == p

solver::Int -> [(Int,[Int])] -> Int
solver n dat = let all_pat = gen_all_pat n  in
               (length.filter (\ ar -> and [gen_checker d ar|d<-dat] )) all_pat

main::IO()
main=do
  n:m:_<- return .map read. words=<< getLine
  dat_r<- forM [1..m] (\_-> return.tail.map read.words=<<getLine)
  dat_l<- return.map read.words=<<getLine
  print (solver n (zip dat_l dat_r))
