import Control.Monad

main = do
  li <- getLine
  let [n,m] = map read $ words li
  ass <- forM [1..m] (\_ -> do
    li <- getLine
    let as = map read $ words li
    return (tail as)
   )
   li <- getLine
   let ps = map read $ words li
   let answer = compute n ass ps
   print answer
 
 compute n ass ps = length
  [ ()
  | st <- states n
  , and [ isOn bs st p | (bs,p) <- zip bss ps ]
  ]
  where
    bss = map (aij2bs n) ass

states 0 = [ [] ]
states k = let sts = states (pred k)
           in  map (0 :) sts ++ map (1 :) sts

aij2bs n ss = [ elem i ss | i <- [1..n] ]

isOn bs st p = even $ p + sum [ s | (b,s) <- zip bs st, b ]
