import Control.Monad
import qualified Data.Map as Map
import Data.List

f2::Int->[Int]->Map.Map Int [Int]->Map.Map Int [Int]
f2 _ [] ms=ms
f2 n (e:es) ms=f2 n es (Map.insertWith (++) e [n] ms)

f::Int->[[Int]]->Map.Map Int [Int]->Map.Map Int [Int]
f _ [] ms=ms
f n (e:es) ms=f (n+1) es (f2 n e ms)

g2::Int->[Int]->[Int]->[Int]
g2 _ _ [] =[]
g2 no [] (x:xs)=x:g2 (no+1) [] xs 
g2 no (t:ts) (x:xs)
          |no==t=(x+1):(g2 (no+1) ts xs)
          |otherwise=x:(g2 (no+1) (t:ts) xs)

g::[[Int]]->[Int]->[Int]->Int
g [] xs ans=foldl1 (*) $ [if (mod x 2)==(mod y 2) then 1::Int else 0::Int|(x,y)<-(zip xs ans)]
g (e:es) xs ans=(g es xs ans)+(g es (g2 1 e xs) ans)


main = do
       t1<-getLine
       let n:m:[]=map read (words t1)::[Int]
       ts<-replicateM m getLine
       ks<-getLine
       let ts2=map tail $ map (map read . words) ts::[[Int]]
           ks2=map read (words ks)::[Int]
           ts3=map sort $ Map.elems $ f 1 ts2 (Map.fromList [])
       print $ (2^(n-(length ts3))) * ( g ts3 [0|e<-[1..m]] ks2)