{-# LANGUAGE BangPatterns      #-} --引数に!

import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as BS

cnt :: [[Int]] -> [Int] -> Int -> Bool
cnt [] _ _ = True
cnt ((k:ss):ls) (p:ps) switches =
  if (==) p $ (`mod`2).sum $ map (\i -> if testBit switches (i-1) then 1 else 0) ss
    then True && (cnt ls ps switches)
    else False

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine :: IO [Int]
  list <- replicateM m $ map read.words <$> getLine :: IO [[Int]]
  ps <- map read.words <$> getLine :: IO [Int]
  let maxint = 2^n-1
  ans <- forM [0..maxint] $ \switches -> do
    return $ cnt list ps switches
  print $ length $ filter (==True) ans
