import Control.Monad

import Data.Ord
import Data.List
import Data.Function
import Data.Maybe

import qualified Data.ByteString.Char8 as BS

import Debug.Trace

tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
  [nSw,nLight] <- getIntList
  ss <- getIntNList nLight
  swAllOn <- getIntList
  let swMatrix = map (indexToVec nSw 1 . drop 1) ss
  print . sum . map (f swAllOn swMatrix) $ allSw nSw

indexToVec :: Int -> Int -> [Int] -> [Int]
indexToVec n i [] = take (n-i) [0..]
indexToVec n i indices@(x:xs)
  | x == i    = (1 : indexToVec n (i+1) xs)
  | otherwise = (0 : indexToVec n (i+1) indices)

f :: [Int] -> [[Int]] -> [Int] -> Int
f ps swMatrix sw
  | ps' == ps = 1
  | otherwise  = 0
  where
    ps' = map (flip mod 2 . sum . zipWith (*) sw) swMatrix

allSw :: Int -> [[Int]]
allSw 0 = [[]]
allSw n = [x:y | x <- [0,1], y <- allSw (n-1)]
