import Control.Monad (replicateM)
import Data.List

main :: IO ()
main = do
  [n,m] <- map (read :: String -> Int) . words <$> getLine
  ksi <- map (tail . map (read :: String -> Int) . words) <$> getNLine_ m
  pm <- map (read :: String -> Int) . words <$> getLine
  let pks = zipWith (mySubsequences n) pm ksi
  print $ length $ foldl1 (intersectBy myeq) pks

myeq :: [Int] -> [Int] -> Bool
myeq xs ys = (xs \\ ys) == [] && (ys \\ xs) == []

mySubsequences :: Int -> Int -> [Int] -> [[Int]]
mySubsequences n b xs
  | b == 0 = map (++ ([1..n] \\ xs)) . filter (\k -> even $ length k) . subsequences $ xs
  | b == 1 = map (++ ([1..n] \\ xs)) . filter (\k -> odd $ length k) . subsequences $ xs

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine