import Control.Monad
import Data.Bits

conv :: [Int] -> Int
conv [] = 0
conv (x:xs) = setBit (conv xs) x

bitCount :: Int -> Int
bitCount 0 = 0
bitCount n = 1 + bitCount (n .&. (n - 1))

main :: IO ()
main = do 
    line <- getLine

    let [n, m] = map read $ words line :: [Int]

    lines <- replicateM m getLine

    let switch = map (conv . drop 1 . map ((subtract 1).read)) $ map words lines :: [Int]

    line2 <- getLine

    let bits = map ( == "1"  ) $ words line2 :: [Bool]

    let z = zip switch bits

    let results = do
        i <- [0..(2 ^ n - 1)]

        let results = do
            (_switch,_bits) <- z
            return $ _bits == (odd $ bitCount $ i .&. _switch )
        
        return $ all id results 

    print $ length $ filter id results
 
