{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> V.Vector (Int, VU.Vector Int) -> VU.Vector Int -> Int
solve !n !m !kss !pn =
  length
    $ filter id
    $ map
        (\(!ls) -> V.all
          (\(!i, (_, !sn)) ->
            let ons = VU.length $ VU.filter id $ VU.map (ls V.!) sn
            in  ons `mod` 2 == pn VU.! i
          )
          (V.indexed kss)
        )
    $ V.replicateM n [True, False]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  kss <- V.replicateM m $ do
    s <- B.getLine
    let (s1, s2)     = B.span (/= ' ') s
    let Just (k1, _) = B.readInt s1
    return (k1, VU.map (\n -> n - 1) $ VU.unfoldrN k1 readInt $ B.tail s2)
  pn <- VU.unfoldrN m readInt <$> B.getLine

  print $ solve n m kss pn
