import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Array as A

main :: IO ()
main = do
  (n : m : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    switchPatterns = map (A.array (1, n)) . sequence . replicate n $ [False, True] :: IO [A.Array Int Bool]
  sss <- sequence . replicate m $ tail . map unsafeSignedDecimal . T.words <$> T.getLine :: IO [[Int]]
  ps <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    f :: A.Array Int Bool -> Bool
    f bs = all ((==) <$> (`div` 2) . length . filter (== True) . map (bs A.!) . fst <*> snd) $ zip sss ps
  print . length . filter f $ switchPatterns

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
