import Control.Monad
import Data.List
import Data.Bool

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

solve :: Int->Int->[[Int]]->[Int]->Int
solve n m kss ps = length ans
  where
  ans = filter and cs
  cs = map g sws
  sws = replicateM n [True,False] :: [[Bool]]
  g sw = map ($ sw) evs
  evs = zipWith (.) eqs cts
  eqs = map (\a->(==a)) ps
  cts = map h kss
  h :: [Int] -> ([Bool] -> Int)
  h ks = bool 0 1 . go 1 ss
    where
    go :: Int -> [Int] -> [Bool] -> Bool
    go _ _ [] = False
    go _ [] _ = False
    go n (s:ss) (l:ls)
      | n == s = l ^^ go (n+1) ss ls
      | otherwise = go (n+1) (s:ss) ls
    ss = sort $ tail ks
    True ^^ True = False
    True ^^ False = True
    False ^^ True = True
    False ^^ False = False
