import Control.Monad
import Data.List

check :: [Int] -> [[Int]] -> [Int] -> Bool
check _ [] [] = True
check sw (s:ss) (p:ps) = if (sum [sw!!(i-1) | i<-s]) `mod` 2 == p then check sw ss ps else False


main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  dat <- replicateM m $ do
    (k:s) <- map read . words <$> getLine :: IO [Int]
    return s
  ps <- map read . words <$> getLine :: IO [Int]

  let ans =
        length . filter id . concat $
        (flip map) [take i (repeat 0) ++ take (n-i) (repeat 1) | i<-[0..n]]
        (\s -> (flip map) (nub $ permutations s) $ \t -> check t dat ps)

  print ans
