import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, m] <- getIntList
    sss <- map tail <$> replicateM m getIntList
    ssps <-zip sss <$> getIntList
    let bss = sequence $ replicate n [False, True]
    print $ length [() | bs <- bss, solve bs ssps]

solve bs ssps = and $ map (check bs) ssps
check bs (ss, p) = (\i -> i `mod` 2 == p) . length . filter id $ map (\i -> bs !! (i - 1)) ss