import Control.Monad ( replicateM )
import Data.Bits ( xor )

f  2 = (\a b -> [a, b]) <$> [0, 1] <*> [0, 1]
f  3 = (\a b c -> [a, b, c]) <$> [0, 1] <*> [0, 1] <*> [0, 1]
f  4 = (\a b c d -> [a, b, c, d]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  5 = (\a b c d e -> [a, b, c, d, e]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  6 = (\a b c d e f -> [a, b, c, d, e, f]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  7 = (\a b c d e f g -> [a, b, c, d, e, f, g]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  8 = (\a b c d e f g h -> [a, b, c, d, e, f, g, h]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  9 = (\a b c d e f g h i -> [a, b, c, d, e, f, g, h, i]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f 10 = (\a b c d e f g h i j -> [a, b, c, d, e, f, g, h, i, j]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]

check :: [Int] -> Int -> [Int] -> Bool
check switches p ks = p == foldl1 xor $ map (switches!!) ks

checkAll :: [Int] -> [Int] -> [[Int]] -> Bool
checkAll switches ps kss = all (uncurry (check switches)) (zip ps kss)

main = do
    [n, m] <- map read . words <$> getLine
    kss <- replicateM m $ map read . words <$> getLine
    ps <- map read . words <$> getLine
    let switchess = f n

    print $ length $ filter (\switches -> checkAll switches ps (map (tail . map pred) kss)) switchess
