import Data.List
import Control.Monad
import qualified Data.IntMap as IM
import Data.Maybe

type Map = IM.IntMap Int

solve :: [(Int, [Int])] -> [Map] -> [Bool]
solve pss [] = []
solve pss (m:ms) = res : solve pss ms
  where res = and $ check pss m

check :: [(Int, [Int])] -> Map -> [Bool]
check [] _ = []
check ((p, ss):pss) m = res : check pss m
  where res = calc ss m `mod` 2 == p

calc :: [Int] -> Map -> Int
calc [] _ = 0
calc (s:ss) m = res + calc ss m
  where res = fromJust $ IM.lookup s m

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  kss <- replicateM m $ tail . map read . words <$> getLine :: IO [[Int]]
  ps <- map read . words <$> getLine :: IO [Int]
  let pss = zip ps kss
  let ms = IM.fromList . zip [1..] <$> replicateM n [0, 1]
  print . length . filter (==True) $ solve pss ms